<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span id="local-6989586621680916207"><span id="local-6989586621680916208"></span></span><span class="hs-comment">{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1992-1998

\section[InstEnv]{Utilities for typechecking instance declarations}

The bits common to GHC.Tc.TyCl.Instance and GHC.Tc.Deriv.
-}</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-pragma">{-# LANGUAGE CPP, DeriveDataTypeable #-}</span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Core.InstEnv</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-13"></span><span>        </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier">DFunId</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier">InstMatch</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInstLookupResult"><span class="hs-identifier">ClsInstLookupResult</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-14"></span><span>        </span><span class="annot"><a href="GHC.Types.Basic.html#OverlapFlag"><span class="hs-identifier">OverlapFlag</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OverlapMode"><span class="hs-identifier">OverlapMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#setOverlapModeMaybe"><span class="hs-identifier">setOverlapModeMaybe</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-15"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier">ClsInst</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#DFunInstType"><span class="hs-identifier">DFunInstType</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#pprInstance"><span class="hs-identifier">pprInstance</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#pprInstanceHdr"><span class="hs-identifier">pprInstanceHdr</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#pprInstances"><span class="hs-identifier">pprInstances</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-16"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceHead"><span class="hs-identifier">instanceHead</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceSig"><span class="hs-identifier">instanceSig</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#mkLocalInstance"><span class="hs-identifier">mkLocalInstance</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#mkImportedInstance"><span class="hs-identifier">mkImportedInstance</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-17"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceDFunId"><span class="hs-identifier">instanceDFunId</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#updateClsInstDFun"><span class="hs-identifier">updateClsInstDFun</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceRoughTcs"><span class="hs-identifier">instanceRoughTcs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-18"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#fuzzyClsInstCmp"><span class="hs-identifier">fuzzyClsInstCmp</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#orphNamesOfClsInst"><span class="hs-identifier">orphNamesOfClsInst</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-19"></span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier">InstEnvs</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#VisibleOrphanModules"><span class="hs-identifier">VisibleOrphanModules</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier">InstEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#emptyInstEnv"><span class="hs-identifier">emptyInstEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#extendInstEnv"><span class="hs-identifier">extendInstEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#deleteFromInstEnv"><span class="hs-identifier">deleteFromInstEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#deleteDFunFromInstEnv"><span class="hs-identifier">deleteDFunFromInstEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#identicalClsInstHead"><span class="hs-identifier">identicalClsInstHead</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-24"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#extendInstEnvList"><span class="hs-identifier">extendInstEnvList</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#lookupUniqueInstEnv"><span class="hs-identifier">lookupUniqueInstEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#lookupInstEnv"><span class="hs-identifier">lookupInstEnv</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#instEnvElts"><span class="hs-identifier">instEnvElts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#instEnvClasses"><span class="hs-identifier">instEnvClasses</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-25"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#memberInstEnv"><span class="hs-identifier">memberInstEnv</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-26"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#instIsVisible"><span class="hs-identifier">instIsVisible</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#classInstances"><span class="hs-identifier">classInstances</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceBindFun"><span class="hs-identifier">instanceBindFun</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="GHC.Core.Unify.html#instanceCantMatch"><span class="hs-identifier">instanceCantMatch</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html#roughMatchTcs"><span class="hs-identifier">roughMatchTcs</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="GHC.Core.InstEnv.html#isOverlappable"><span class="hs-identifier">isOverlappable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#isOverlapping"><span class="hs-identifier">isOverlapping</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier">isIncoherent</span></a></span><span>
</span><span id="line-30"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span class="hs-cpp">

#include &quot;HsVersions.h&quot;
</span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span> </span><span class="hs-comment">-- InstEnv is really part of the type checker,</span><span>
</span><span id="line-37"></span><span>              </span><span class="hs-comment">-- and depends on TcType in many ways</span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.html"><span class="hs-identifier">GHC.Core</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.html#IsOrphan"><span class="hs-identifier">IsOrphan</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#isOrphan"><span class="hs-identifier">isOrphan</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.html#chooseOrphanAnchor"><span class="hs-identifier">chooseOrphanAnchor</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Unit.html"><span class="hs-identifier">GHC.Unit</span></a></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Class.html"><span class="hs-identifier">GHC.Core.Class</span></a></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span>
</span><span id="line-42"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.html"><span class="hs-identifier">GHC.Types.Name</span></a></span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Name.Set.html"><span class="hs-identifier">GHC.Types.Name.Set</span></a></span><span>
</span><span id="line-45"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Unique.html"><span class="hs-identifier">GHC.Types.Unique</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Unique.html#getUnique"><span class="hs-identifier">getUnique</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html"><span class="hs-identifier">GHC.Core.Unify</span></a></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Error.html"><span class="hs-identifier">GHC.Utils.Error</span></a></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Unique.DFM.html"><span class="hs-identifier">GHC.Types.Unique.DFM</span></a></span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Misc.html"><span class="hs-identifier">GHC.Utils.Misc</span></a></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Data.html#"><span class="hs-identifier">Data.Data</span></a></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Data.html#Data"><span class="hs-identifier">Data</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#"><span class="hs-identifier">Data.Maybe</span></a></span><span>       </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier">isJust</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/Data.Maybe.html#isNothing"><span class="hs-identifier">isNothing</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
           ClsInst: the data type for type-class instances
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span class="hs-comment">-- | A type-class instance. Note that there is some tricky laziness at work</span><span>
</span><span id="line-65"></span><span class="hs-comment">-- here. See Note [ClsInst laziness and the rough-match fields] for more</span><span>
</span><span id="line-66"></span><span class="hs-comment">-- details.</span><span>
</span><span id="line-67"></span><span class="hs-keyword">data</span><span> </span><span id="ClsInst"><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-var">ClsInst</span></a></span></span><span>
</span><span id="line-68"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="ClsInst"><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-var">ClsInst</span></a></span></span><span> </span><span class="hs-special">{</span><span>   </span><span class="hs-comment">-- Used for &quot;rough matching&quot;; see</span><span>
</span><span id="line-69"></span><span>                </span><span class="hs-comment">-- Note [ClsInst laziness and the rough-match fields]</span><span>
</span><span id="line-70"></span><span>                </span><span class="hs-comment">-- INVARIANT: is_tcs = roughMatchTcs is_tys</span><span>
</span><span id="line-71"></span><span>               </span><span id="is_cls_nm"><span class="annot"><span class="annottext">ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var hs-var">is_cls_nm</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span>        </span><span class="hs-comment">-- ^ Class name</span><span>
</span><span id="line-72"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_tcs"><span class="annot"><span class="annottext">ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var hs-var">is_tcs</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- ^ Top of type args</span><span>
</span><span id="line-73"></span><span>
</span><span id="line-74"></span><span>               </span><span class="hs-comment">-- | @is_dfun_name = idName . is_dfun@.</span><span>
</span><span id="line-75"></span><span>               </span><span class="hs-comment">--</span><span>
</span><span id="line-76"></span><span>               </span><span class="hs-comment">-- We use 'is_dfun_name' for the visibility check,</span><span>
</span><span id="line-77"></span><span>               </span><span class="hs-comment">-- 'instIsVisible', which needs to know the 'Module' which the</span><span>
</span><span id="line-78"></span><span>               </span><span class="hs-comment">-- dictionary is defined in. However, we cannot use the 'Module'</span><span>
</span><span id="line-79"></span><span>               </span><span class="hs-comment">-- attached to 'is_dfun' since doing so would mean we would</span><span>
</span><span id="line-80"></span><span>               </span><span class="hs-comment">-- potentially pull in an entire interface file unnecessarily.</span><span>
</span><span id="line-81"></span><span>               </span><span class="hs-comment">-- This was the cause of #12367.</span><span>
</span><span id="line-82"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_dfun_name"><span class="annot"><span class="annottext">ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_dfun_name"><span class="hs-identifier hs-var hs-var">is_dfun_name</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span>
</span><span id="line-83"></span><span>
</span><span id="line-84"></span><span>                </span><span class="hs-comment">-- Used for &quot;proper matching&quot;; see Note [Proper-match fields]</span><span>
</span><span id="line-85"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_tvs"><span class="annot"><span class="annottext">ClsInst -&gt; [DFunId]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var hs-var">is_tvs</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span>       </span><span class="hs-comment">-- Fresh template tyvars for full match</span><span>
</span><span id="line-86"></span><span>                                        </span><span class="hs-comment">-- See Note [Template tyvars are fresh]</span><span>
</span><span id="line-87"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_cls"><span class="annot"><span class="annottext">ClsInst -&gt; Class
</span><a href="GHC.Core.InstEnv.html#is_cls"><span class="hs-identifier hs-var hs-var">is_cls</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span>         </span><span class="hs-comment">-- The real class</span><span>
</span><span id="line-88"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_tys"><span class="annot"><span class="annottext">ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var hs-var">is_tys</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>        </span><span class="hs-comment">-- Full arg types (mentioning is_tvs)</span><span>
</span><span id="line-89"></span><span>                </span><span class="hs-comment">-- INVARIANT: is_dfun Id has type</span><span>
</span><span id="line-90"></span><span>                </span><span class="hs-comment">--      forall is_tvs. (...) =&gt; is_cls is_tys</span><span>
</span><span id="line-91"></span><span>                </span><span class="hs-comment">-- (modulo alpha conversion)</span><span>
</span><span id="line-92"></span><span>
</span><span id="line-93"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_dfun"><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span> </span><span class="hs-comment">-- See Note [Haddock assumptions]</span><span>
</span><span id="line-94"></span><span>
</span><span id="line-95"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_flag"><span class="annot"><span class="annottext">ClsInst -&gt; OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var hs-var">is_flag</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OverlapFlag"><span class="hs-identifier hs-type">OverlapFlag</span></a></span><span>   </span><span class="hs-comment">-- See detailed comments with</span><span>
</span><span id="line-96"></span><span>                                        </span><span class="hs-comment">-- the decl of BasicTypes.OverlapFlag</span><span>
</span><span id="line-97"></span><span>             </span><span class="hs-special">,</span><span> </span><span id="is_orphan"><span class="annot"><span class="annottext">ClsInst -&gt; IsOrphan
</span><a href="GHC.Core.InstEnv.html#is_orphan"><span class="hs-identifier hs-var hs-var">is_orphan</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.html#IsOrphan"><span class="hs-identifier hs-type">IsOrphan</span></a></span><span>
</span><span id="line-98"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-99"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span id="local-6989586621680916077"><span id="local-6989586621680916079"><span id="local-6989586621680916081"><span id="local-6989586621680916083"><span id="local-6989586621680916085"><span id="local-6989586621680916087"><span id="local-6989586621680916089"><span id="local-6989586621680916091"><span id="local-6989586621680916093"><span id="local-6989586621680916095"><span id="local-6989586621680916097"><span id="local-6989586621680916099"><span id="local-6989586621680916112"><span id="local-6989586621680916131"><span class="annot"><span class="annottext">Typeable ClsInst
Typeable ClsInst
-&gt; (forall (c :: * -&gt; *).
    (forall d b. Data d =&gt; c (d -&gt; b) -&gt; d -&gt; c b)
    -&gt; (forall g. g -&gt; c g) -&gt; ClsInst -&gt; c ClsInst)
-&gt; (forall (c :: * -&gt; *).
    (forall b r. Data b =&gt; c (b -&gt; r) -&gt; c r)
    -&gt; (forall r. r -&gt; c r) -&gt; Constr -&gt; c ClsInst)
-&gt; (ClsInst -&gt; Constr)
-&gt; (ClsInst -&gt; DataType)
-&gt; (forall (t :: * -&gt; *) (c :: * -&gt; *).
    Typeable t =&gt;
    (forall d. Data d =&gt; c (t d)) -&gt; Maybe (c ClsInst))
-&gt; (forall (t :: * -&gt; * -&gt; *) (c :: * -&gt; *).
    Typeable t =&gt;
    (forall d e. (Data d, Data e) =&gt; c (t d e)) -&gt; Maybe (c ClsInst))
-&gt; ((forall b. Data b =&gt; b -&gt; b) -&gt; ClsInst -&gt; ClsInst)
-&gt; (forall r r'.
    (r -&gt; r' -&gt; r)
    -&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r)
-&gt; (forall r r'.
    (r' -&gt; r -&gt; r)
    -&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r)
-&gt; (forall u. (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; [u])
-&gt; (forall u. Int -&gt; (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; u)
-&gt; (forall (m :: * -&gt; *).
    Monad m =&gt;
    (forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst)
-&gt; (forall (m :: * -&gt; *).
    MonadPlus m =&gt;
    (forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst)
-&gt; (forall (m :: * -&gt; *).
    MonadPlus m =&gt;
    (forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst)
-&gt; Data ClsInst
ClsInst -&gt; DataType
ClsInst -&gt; Constr
(forall b. Data b =&gt; b -&gt; b) -&gt; ClsInst -&gt; ClsInst
forall a.
Typeable a
-&gt; (forall (c :: * -&gt; *).
    (forall d b. Data d =&gt; c (d -&gt; b) -&gt; d -&gt; c b)
    -&gt; (forall g. g -&gt; c g) -&gt; a -&gt; c a)
-&gt; (forall (c :: * -&gt; *).
    (forall b r. Data b =&gt; c (b -&gt; r) -&gt; c r)
    -&gt; (forall r. r -&gt; c r) -&gt; Constr -&gt; c a)
-&gt; (a -&gt; Constr)
-&gt; (a -&gt; DataType)
-&gt; (forall (t :: * -&gt; *) (c :: * -&gt; *).
    Typeable t =&gt;
    (forall d. Data d =&gt; c (t d)) -&gt; Maybe (c a))
-&gt; (forall (t :: * -&gt; * -&gt; *) (c :: * -&gt; *).
    Typeable t =&gt;
    (forall d e. (Data d, Data e) =&gt; c (t d e)) -&gt; Maybe (c a))
-&gt; ((forall b. Data b =&gt; b -&gt; b) -&gt; a -&gt; a)
-&gt; (forall r r'.
    (r -&gt; r' -&gt; r) -&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; a -&gt; r)
-&gt; (forall r r'.
    (r' -&gt; r -&gt; r) -&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; a -&gt; r)
-&gt; (forall u. (forall d. Data d =&gt; d -&gt; u) -&gt; a -&gt; [u])
-&gt; (forall u. Int -&gt; (forall d. Data d =&gt; d -&gt; u) -&gt; a -&gt; u)
-&gt; (forall (m :: * -&gt; *).
    Monad m =&gt;
    (forall d. Data d =&gt; d -&gt; m d) -&gt; a -&gt; m a)
-&gt; (forall (m :: * -&gt; *).
    MonadPlus m =&gt;
    (forall d. Data d =&gt; d -&gt; m d) -&gt; a -&gt; m a)
-&gt; (forall (m :: * -&gt; *).
    MonadPlus m =&gt;
    (forall d. Data d =&gt; d -&gt; m d) -&gt; a -&gt; m a)
-&gt; Data a
forall u. Int -&gt; (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; u
forall u. (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; [u]
forall r r'.
(r -&gt; r' -&gt; r)
-&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r
forall r r'.
(r' -&gt; r -&gt; r)
-&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r
forall (m :: * -&gt; *).
Monad m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
forall (m :: * -&gt; *).
MonadPlus m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
forall (c :: * -&gt; *).
(forall b r. Data b =&gt; c (b -&gt; r) -&gt; c r)
-&gt; (forall r. r -&gt; c r) -&gt; Constr -&gt; c ClsInst
forall (c :: * -&gt; *).
(forall d b. Data d =&gt; c (d -&gt; b) -&gt; d -&gt; c b)
-&gt; (forall g. g -&gt; c g) -&gt; ClsInst -&gt; c ClsInst
forall (t :: * -&gt; *) (c :: * -&gt; *).
Typeable t =&gt;
(forall d. Data d =&gt; c (t d)) -&gt; Maybe (c ClsInst)
forall (t :: * -&gt; * -&gt; *) (c :: * -&gt; *).
Typeable t =&gt;
(forall d e. (Data d, Data e) =&gt; c (t d e)) -&gt; Maybe (c ClsInst)
gmapMo :: forall (m :: * -&gt; *).
MonadPlus m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
$cgmapMo :: forall (m :: * -&gt; *).
MonadPlus m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
gmapMp :: forall (m :: * -&gt; *).
MonadPlus m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
$cgmapMp :: forall (m :: * -&gt; *).
MonadPlus m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
gmapM :: forall (m :: * -&gt; *).
Monad m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
$cgmapM :: forall (m :: * -&gt; *).
Monad m =&gt;
(forall d. Data d =&gt; d -&gt; m d) -&gt; ClsInst -&gt; m ClsInst
gmapQi :: forall u. Int -&gt; (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; u
$cgmapQi :: forall u. Int -&gt; (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; u
gmapQ :: forall u. (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; [u]
$cgmapQ :: forall u. (forall d. Data d =&gt; d -&gt; u) -&gt; ClsInst -&gt; [u]
gmapQr :: forall r r'.
(r' -&gt; r -&gt; r)
-&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r
$cgmapQr :: forall r r'.
(r' -&gt; r -&gt; r)
-&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r
gmapQl :: forall r r'.
(r -&gt; r' -&gt; r)
-&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r
$cgmapQl :: forall r r'.
(r -&gt; r' -&gt; r)
-&gt; r -&gt; (forall d. Data d =&gt; d -&gt; r') -&gt; ClsInst -&gt; r
gmapT :: (forall b. Data b =&gt; b -&gt; b) -&gt; ClsInst -&gt; ClsInst
$cgmapT :: (forall b. Data b =&gt; b -&gt; b) -&gt; ClsInst -&gt; ClsInst
dataCast2 :: forall (t :: * -&gt; * -&gt; *) (c :: * -&gt; *).
Typeable t =&gt;
(forall d e. (Data d, Data e) =&gt; c (t d e)) -&gt; Maybe (c ClsInst)
$cdataCast2 :: forall (t :: * -&gt; * -&gt; *) (c :: * -&gt; *).
Typeable t =&gt;
(forall d e. (Data d, Data e) =&gt; c (t d e)) -&gt; Maybe (c ClsInst)
dataCast1 :: forall (t :: * -&gt; *) (c :: * -&gt; *).
Typeable t =&gt;
(forall d. Data d =&gt; c (t d)) -&gt; Maybe (c ClsInst)
$cdataCast1 :: forall (t :: * -&gt; *) (c :: * -&gt; *).
Typeable t =&gt;
(forall d. Data d =&gt; c (t d)) -&gt; Maybe (c ClsInst)
dataTypeOf :: ClsInst -&gt; DataType
$cdataTypeOf :: ClsInst -&gt; DataType
toConstr :: ClsInst -&gt; Constr
$ctoConstr :: ClsInst -&gt; Constr
gunfold :: forall (c :: * -&gt; *).
(forall b r. Data b =&gt; c (b -&gt; r) -&gt; c r)
-&gt; (forall r. r -&gt; c r) -&gt; Constr -&gt; c ClsInst
$cgunfold :: forall (c :: * -&gt; *).
(forall b r. Data b =&gt; c (b -&gt; r) -&gt; c r)
-&gt; (forall r. r -&gt; c r) -&gt; Constr -&gt; c ClsInst
gfoldl :: forall (c :: * -&gt; *).
(forall d b. Data d =&gt; c (d -&gt; b) -&gt; d -&gt; c b)
-&gt; (forall g. g -&gt; c g) -&gt; ClsInst -&gt; c ClsInst
$cgfoldl :: forall (c :: * -&gt; *).
(forall d b. Data d =&gt; c (d -&gt; b) -&gt; d -&gt; c b)
-&gt; (forall g. g -&gt; c g) -&gt; ClsInst -&gt; c ClsInst
</span><a href="../../base/src/Data.Data.html#Data"><span class="hs-identifier hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">Data</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="hs-comment">-- | A fuzzy comparison function for class instances, intended for sorting</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- instances before displaying them to the user.</span><span>
</span><span id="line-103"></span><span class="annot"><a href="GHC.Core.InstEnv.html#fuzzyClsInstCmp"><span class="hs-identifier hs-type">fuzzyClsInstCmp</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Ordering</span></span><span>
</span><span id="line-104"></span><span id="fuzzyClsInstCmp"><span class="annot"><span class="annottext">fuzzyClsInstCmp :: ClsInst -&gt; ClsInst -&gt; Ordering
</span><a href="GHC.Core.InstEnv.html#fuzzyClsInstCmp"><span class="hs-identifier hs-var hs-var">fuzzyClsInstCmp</span></a></span></span><span> </span><span id="local-6989586621680916073"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916073"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621680916072"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916072"><span class="hs-identifier hs-var">y</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-105"></span><span>    </span><span class="annot"><span class="annottext">Name -&gt; Name -&gt; Ordering
</span><a href="GHC.Types.Name.html#stableNameCmp"><span class="hs-identifier hs-var">stableNameCmp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var hs-var">is_cls_nm</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916073"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var hs-var">is_cls_nm</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916072"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ordering -&gt; Ordering -&gt; Ordering
forall a. Monoid a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Base.html#mappend"><span class="hs-operator hs-var">`mappend`</span></a></span><span>
</span><span id="line-106"></span><span>    </span><span class="annot"><span class="annottext">[Ordering] -&gt; Ordering
forall a. Monoid a =&gt; [a] -&gt; a
</span><a href="../../base/src/GHC.Base.html#mconcat"><span class="hs-identifier hs-var">mconcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Maybe Name, Maybe Name) -&gt; Ordering)
-&gt; [(Maybe Name, Maybe Name)] -&gt; [Ordering]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Maybe Name, Maybe Name) -&gt; Ordering
</span><a href="#local-6989586621680916070"><span class="hs-identifier hs-var">cmp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; [(Maybe Name, Maybe Name)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-identifier hs-var">zip</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var hs-var">is_tcs</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916073"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var hs-var">is_tcs</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916072"><span class="hs-identifier hs-var">y</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-108"></span><span>    </span><span id="local-6989586621680916070"><span class="annot"><span class="annottext">cmp :: (Maybe Name, Maybe Name) -&gt; Ordering
</span><a href="#local-6989586621680916070"><span class="hs-identifier hs-var hs-var">cmp</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Name
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe Name
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">EQ</span></span><span>
</span><span id="line-109"></span><span>    </span><span class="annot"><a href="#local-6989586621680916070"><span class="hs-identifier hs-var">cmp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Name
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">LT</span></span><span>
</span><span id="line-110"></span><span>    </span><span class="annot"><a href="#local-6989586621680916070"><span class="hs-identifier hs-var">cmp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe Name
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ordering
</span><span class="hs-identifier hs-var">GT</span></span><span>
</span><span id="line-111"></span><span>    </span><span class="annot"><a href="#local-6989586621680916070"><span class="hs-identifier hs-var">cmp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680916069"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916069"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680916068"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916068"><span class="hs-identifier hs-var">y</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name -&gt; Ordering
</span><a href="GHC.Types.Name.html#stableNameCmp"><span class="hs-identifier hs-var">stableNameCmp</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916069"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916068"><span class="hs-identifier hs-var">y</span></a></span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="annot"><a href="GHC.Core.InstEnv.html#isOverlappable"><span class="hs-identifier hs-type">isOverlappable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#isOverlapping"><span class="hs-identifier hs-type">isOverlapping</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier hs-type">isIncoherent</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-114"></span><span id="isOverlappable"><span class="annot"><span class="annottext">isOverlappable :: ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isOverlappable"><span class="hs-identifier hs-var hs-var">isOverlappable</span></a></span></span><span> </span><span id="local-6989586621680916067"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916067"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OverlapMode -&gt; Bool
</span><a href="GHC.Types.Basic.html#hasOverlappableFlag"><span class="hs-identifier hs-var">hasOverlappableFlag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OverlapFlag -&gt; OverlapMode
</span><a href="GHC.Types.Basic.html#overlapMode"><span class="hs-identifier hs-var hs-var">overlapMode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var hs-var">is_flag</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916067"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span id="isOverlapping"><span class="annot"><span class="annottext">isOverlapping :: ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isOverlapping"><span class="hs-identifier hs-var hs-var">isOverlapping</span></a></span></span><span>  </span><span id="local-6989586621680916064"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916064"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OverlapMode -&gt; Bool
</span><a href="GHC.Types.Basic.html#hasOverlappingFlag"><span class="hs-identifier hs-var">hasOverlappingFlag</span></a></span><span>  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OverlapFlag -&gt; OverlapMode
</span><a href="GHC.Types.Basic.html#overlapMode"><span class="hs-identifier hs-var hs-var">overlapMode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var hs-var">is_flag</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916064"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-116"></span><span id="isIncoherent"><span class="annot"><span class="annottext">isIncoherent :: ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier hs-var hs-var">isIncoherent</span></a></span></span><span>   </span><span id="local-6989586621680916062"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916062"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OverlapMode -&gt; Bool
</span><a href="GHC.Types.Basic.html#hasIncoherentFlag"><span class="hs-identifier hs-var">hasIncoherentFlag</span></a></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">OverlapFlag -&gt; OverlapMode
</span><a href="GHC.Types.Basic.html#overlapMode"><span class="hs-identifier hs-var hs-var">overlapMode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var hs-var">is_flag</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916062"><span class="hs-identifier hs-var">i</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-117"></span><span>
</span><span id="line-118"></span><span class="hs-comment">{-
Note [ClsInst laziness and the rough-match fields]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we load 'instance A.C B.T' from A.hi, but suppose that the type B.T is
otherwise unused in the program. Then it's stupid to load B.hi, the data type
declaration for B.T -- and perhaps further instance declarations!

We avoid this as follows:

* is_cls_nm, is_tcs, is_dfun_name are all Names. We can poke them to our heart's
  content.

* Proper-match fields. is_dfun, and its related fields is_tvs, is_cls, is_tys
  contain TyVars, Class, Type, Class etc, and so are all lazy thunks. When we
  poke any of these fields we'll typecheck the DFunId declaration, and hence
  pull in interfaces that it refers to. See Note [Proper-match fields].

* Rough-match fields. During instance lookup, we use the is_cls_nm :: Name and
  is_tcs :: [Maybe Name] fields to perform a &quot;rough match&quot;, *without* poking
  inside the DFunId. The rough-match fields allow us to say &quot;definitely does not
  match&quot;, based only on Names.

  This laziness is very important; see #12367. Try hard to avoid pulling on
  the structured fields unless you really need the instance.

* Another place to watch is InstEnv.instIsVisible, which needs the module to
  which the ClsInst belongs. We can get this from is_dfun_name.

* In is_tcs,
    Nothing  means that this type arg is a type variable

    (Just n) means that this type arg is a
                TyConApp with a type constructor of n.
                This is always a real tycon, never a synonym!
                (Two different synonyms might match, but two
                different real tycons can't.)
                NB: newtypes are not transparent, though!
-}</span><span>
</span><span id="line-156"></span><span>
</span><span id="line-157"></span><span class="hs-comment">{-
Note [Template tyvars are fresh]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The is_tvs field of a ClsInst has *completely fresh* tyvars.
That is, they are
  * distinct from any other ClsInst
  * distinct from any tyvars free in predicates that may
    be looked up in the class instance environment
Reason for freshness: we use unification when checking for overlap
etc, and that requires the tyvars to be distinct.

The invariant is checked by the ASSERT in lookupInstEnv'.

Note [Proper-match fields]
~~~~~~~~~~~~~~~~~~~~~~~~~
The is_tvs, is_cls, is_tys fields are simply cached values, pulled
out (lazily) from the dfun id. They are cached here simply so
that we don't need to decompose the DFunId each time we want
to match it.  The hope is that the rough-match fields mean
that we often never poke the proper-match fields.

However, note that:
 * is_tvs must be a superset of the free vars of is_tys

 * is_tvs, is_tys may be alpha-renamed compared to the ones in
   the dfun Id

Note [Haddock assumptions]
~~~~~~~~~~~~~~~~~~~~~~~~~~
For normal user-written instances, Haddock relies on

 * the SrcSpan of
 * the Name of
 * the is_dfun of
 * an Instance

being equal to

  * the SrcSpan of
  * the instance head type of
  * the InstDecl used to construct the Instance.
-}</span><span>
</span><span id="line-199"></span><span>
</span><span id="line-200"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceDFunId"><span class="hs-identifier hs-type">instanceDFunId</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span>
</span><span id="line-201"></span><span id="instanceDFunId"><span class="annot"><span class="annottext">instanceDFunId :: ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#instanceDFunId"><span class="hs-identifier hs-var hs-var">instanceDFunId</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span>
</span><span id="line-202"></span><span>
</span><span id="line-203"></span><span class="annot"><a href="GHC.Core.InstEnv.html#updateClsInstDFun"><span class="hs-identifier hs-type">updateClsInstDFun</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span>
</span><span id="line-204"></span><span id="updateClsInstDFun"><span class="annot"><span class="annottext">updateClsInstDFun :: (DFunId -&gt; DFunId) -&gt; ClsInst -&gt; ClsInst
</span><a href="GHC.Core.InstEnv.html#updateClsInstDFun"><span class="hs-identifier hs-var hs-var">updateClsInstDFun</span></a></span></span><span> </span><span id="local-6989586621680916060"><span class="annot"><span class="annottext">DFunId -&gt; DFunId
</span><a href="#local-6989586621680916060"><span class="hs-identifier hs-var">tidy_dfun</span></a></span></span><span> </span><span id="local-6989586621680916059"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916059"><span class="hs-identifier hs-var">ispec</span></a></span></span><span>
</span><span id="line-205"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916059"><span class="hs-identifier hs-var">ispec</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_dfun :: DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var">is_dfun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; DFunId
</span><a href="#local-6989586621680916060"><span class="hs-identifier hs-var">tidy_dfun</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916059"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-206"></span><span>
</span><span id="line-207"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceRoughTcs"><span class="hs-identifier hs-type">instanceRoughTcs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-208"></span><span id="instanceRoughTcs"><span class="annot"><span class="annottext">instanceRoughTcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#instanceRoughTcs"><span class="hs-identifier hs-var hs-var">instanceRoughTcs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var hs-var">is_tcs</span></a></span><span>
</span><span id="line-209"></span><span>
</span><span id="line-210"></span><span>
</span><span id="line-211"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680916057"><span class="annot"><a href="GHC.Types.Name.html#NamedThing"><span class="hs-identifier hs-type">NamedThing</span></a></span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-212"></span><span>   </span><span id="local-6989586621680916052"><span class="annot"><span class="annottext">getName :: ClsInst -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var hs-var hs-var hs-var">getName</span></a></span></span><span> </span><span id="local-6989586621680916050"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916050"><span class="hs-identifier hs-var">ispec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916050"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-213"></span><span>
</span><span id="line-214"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680916047"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-215"></span><span>   </span><span id="local-6989586621680916045"><span class="annot"><span class="annottext">ppr :: ClsInst -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstance"><span class="hs-identifier hs-var">pprInstance</span></a></span><span>
</span><span id="line-216"></span><span>
</span><span id="line-217"></span><span class="annot"><a href="GHC.Core.InstEnv.html#pprInstance"><span class="hs-identifier hs-type">pprInstance</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-218"></span><span class="hs-comment">-- Prints the ClsInst as an instance declaration</span><span>
</span><span id="line-219"></span><span id="pprInstance"><span class="annot"><span class="annottext">pprInstance :: ClsInst -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstance"><span class="hs-identifier hs-var hs-var">pprInstance</span></a></span></span><span> </span><span id="local-6989586621680916043"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916043"><span class="hs-identifier hs-var">ispec</span></a></span></span><span>
</span><span id="line-220"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Int -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#hang"><span class="hs-identifier hs-var">hang</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstanceHdr"><span class="hs-identifier hs-var">pprInstanceHdr</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916043"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-221"></span><span>       </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;--&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; SDoc
</span><a href="GHC.Types.Name.html#pprDefinedAt"><span class="hs-identifier hs-var">pprDefinedAt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916043"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-222"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#whenPprDebug"><span class="hs-identifier hs-var">whenPprDebug</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916043"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-223"></span><span>
</span><span id="line-224"></span><span class="hs-comment">-- * pprInstanceHdr is used in VStudio to populate the ClassView tree</span><span>
</span><span id="line-225"></span><span class="annot"><a href="GHC.Core.InstEnv.html#pprInstanceHdr"><span class="hs-identifier hs-type">pprInstanceHdr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-226"></span><span class="hs-comment">-- Prints the ClsInst as an instance declaration</span><span>
</span><span id="line-227"></span><span id="pprInstanceHdr"><span class="annot"><span class="annottext">pprInstanceHdr :: ClsInst -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstanceHdr"><span class="hs-identifier hs-var hs-var">pprInstanceHdr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_flag :: ClsInst -&gt; OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var">is_flag</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916036"><span class="annot"><span class="annottext">OverlapFlag
</span><a href="#local-6989586621680916036"><span class="hs-identifier hs-var">flag</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_dfun :: ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var">is_dfun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916035"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916035"><span class="hs-identifier hs-var">dfun</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-228"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;instance&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">OverlapFlag -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">OverlapFlag
</span><a href="#local-6989586621680916036"><span class="hs-identifier hs-var">flag</span></a></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Type -&gt; SDoc
</span><a href="GHC.Core.TyCo.Ppr.html#pprSigmaType"><span class="hs-identifier hs-var">pprSigmaType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916035"><span class="hs-identifier hs-var">dfun</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-229"></span><span>
</span><span id="line-230"></span><span class="annot"><a href="GHC.Core.InstEnv.html#pprInstances"><span class="hs-identifier hs-type">pprInstances</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-231"></span><span id="pprInstances"><span class="annot"><span class="annottext">pprInstances :: [ClsInst] -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstances"><span class="hs-identifier hs-var hs-var">pprInstances</span></a></span></span><span> </span><span id="local-6989586621680916032"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680916032"><span class="hs-identifier hs-var">ispecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[SDoc] -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ClsInst -&gt; SDoc) -&gt; [ClsInst] -&gt; [SDoc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstance"><span class="hs-identifier hs-var">pprInstance</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680916032"><span class="hs-identifier hs-var">ispecs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-232"></span><span>
</span><span id="line-233"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceHead"><span class="hs-identifier hs-type">instanceHead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-234"></span><span class="hs-comment">-- Returns the head, using the fresh tyavs from the ClsInst</span><span>
</span><span id="line-235"></span><span id="instanceHead"><span class="annot"><span class="annottext">instanceHead :: ClsInst -&gt; ([DFunId], Class, [Type])
</span><a href="GHC.Core.InstEnv.html#instanceHead"><span class="hs-identifier hs-var hs-var">instanceHead</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_tvs :: ClsInst -&gt; [DFunId]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916031"><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680916031"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916030"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916030"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_dfun :: ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var">is_dfun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916029"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916029"><span class="hs-identifier hs-var">dfun</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-236"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680916031"><span class="hs-identifier hs-var">tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680916028"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916030"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-237"></span><span>   </span><span class="hs-keyword">where</span><span>
</span><span id="line-238"></span><span>     </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[DFunId]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680916028"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680916028"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; ([DFunId], [Type], Class, [Type])
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitDFunTy"><span class="hs-identifier hs-var">tcSplitDFunTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916029"><span class="hs-identifier hs-var">dfun</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-239"></span><span>
</span><span id="line-240"></span><span class="hs-comment">-- | Collects the names of concrete types and type constructors that make</span><span>
</span><span id="line-241"></span><span class="hs-comment">-- up the head of a class instance. For instance, given `class Foo a b`:</span><span>
</span><span id="line-242"></span><span class="hs-comment">--</span><span>
</span><span id="line-243"></span><span class="hs-comment">-- `instance Foo (Either (Maybe Int) a) Bool` would yield</span><span>
</span><span id="line-244"></span><span class="hs-comment">--      [Either, Maybe, Int, Bool]</span><span>
</span><span id="line-245"></span><span class="hs-comment">--</span><span>
</span><span id="line-246"></span><span class="hs-comment">-- Used in the implementation of &quot;:info&quot; in GHCi.</span><span>
</span><span id="line-247"></span><span class="hs-comment">--</span><span>
</span><span id="line-248"></span><span class="hs-comment">-- The 'tcSplitSigmaTy' is because of</span><span>
</span><span id="line-249"></span><span class="hs-comment">--      instance Foo a =&gt; Baz T where ...</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- The decl is an orphan if Baz and T are both not locally defined,</span><span>
</span><span id="line-251"></span><span class="hs-comment">--      even if Foo *is* locally defined</span><span>
</span><span id="line-252"></span><span class="annot"><a href="GHC.Core.InstEnv.html#orphNamesOfClsInst"><span class="hs-identifier hs-type">orphNamesOfClsInst</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Name.Set.html#NameSet"><span class="hs-identifier hs-type">NameSet</span></a></span><span>
</span><span id="line-253"></span><span id="orphNamesOfClsInst"><span class="annot"><span class="annottext">orphNamesOfClsInst :: ClsInst -&gt; NameSet
</span><a href="GHC.Core.InstEnv.html#orphNamesOfClsInst"><span class="hs-identifier hs-var hs-var">orphNamesOfClsInst</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916026"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916026"><span class="hs-identifier hs-var">cls_nm</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680916025"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916025"><span class="hs-identifier hs-var">tys</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-254"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; NameSet
</span><a href="GHC.Core.FVs.html#orphNamesOfTypes"><span class="hs-identifier hs-var">orphNamesOfTypes</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916025"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="annot"><span class="annottext">NameSet -&gt; NameSet -&gt; NameSet
</span><a href="GHC.Types.Name.Set.html#unionNameSet"><span class="hs-operator hs-var">`unionNameSet`</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; NameSet
</span><a href="GHC.Types.Name.Set.html#unitNameSet"><span class="hs-identifier hs-var">unitNameSet</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916026"><span class="hs-identifier hs-var">cls_nm</span></a></span><span>
</span><span id="line-255"></span><span>
</span><span id="line-256"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceSig"><span class="hs-identifier hs-type">instanceSig</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- Decomposes the DFunId</span><span>
</span><span id="line-258"></span><span id="instanceSig"><span class="annot"><span class="annottext">instanceSig :: ClsInst -&gt; ([DFunId], [Type], Class, [Type])
</span><a href="GHC.Core.InstEnv.html#instanceSig"><span class="hs-identifier hs-var hs-var">instanceSig</span></a></span></span><span> </span><span id="local-6989586621680916021"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916021"><span class="hs-identifier hs-var">ispec</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; ([DFunId], [Type], Class, [Type])
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitDFunTy"><span class="hs-identifier hs-var">tcSplitDFunTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680916021"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-259"></span><span>
</span><span id="line-260"></span><span class="annot"><a href="GHC.Core.InstEnv.html#mkLocalInstance"><span class="hs-identifier hs-type">mkLocalInstance</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OverlapFlag"><span class="hs-identifier hs-type">OverlapFlag</span></a></span><span>
</span><span id="line-261"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TyVar"><span class="hs-identifier hs-type">TyVar</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-262"></span><span>                </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span>
</span><span id="line-263"></span><span class="hs-comment">-- Used for local instances, where we can safely pull on the DFunId.</span><span>
</span><span id="line-264"></span><span class="hs-comment">-- Consider using newClsInst instead; this will also warn if</span><span>
</span><span id="line-265"></span><span class="hs-comment">-- the instance is an orphan.</span><span>
</span><span id="line-266"></span><span id="mkLocalInstance"><span class="annot"><span class="annottext">mkLocalInstance :: DFunId -&gt; OverlapFlag -&gt; [DFunId] -&gt; Class -&gt; [Type] -&gt; ClsInst
</span><a href="GHC.Core.InstEnv.html#mkLocalInstance"><span class="hs-identifier hs-var hs-var">mkLocalInstance</span></a></span></span><span> </span><span id="local-6989586621680916020"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916020"><span class="hs-identifier hs-var">dfun</span></a></span></span><span> </span><span id="local-6989586621680916019"><span class="annot"><span class="annottext">OverlapFlag
</span><a href="#local-6989586621680916019"><span class="hs-identifier hs-var">oflag</span></a></span></span><span> </span><span id="local-6989586621680916018"><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680916018"><span class="hs-identifier hs-var">tvs</span></a></span></span><span> </span><span id="local-6989586621680916017"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680916017"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621680916016"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916016"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-267"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst :: Name
-&gt; [Maybe Name]
-&gt; Name
-&gt; [DFunId]
-&gt; Class
-&gt; [Type]
-&gt; DFunId
-&gt; OverlapFlag
-&gt; IsOrphan
-&gt; ClsInst
</span><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_flag :: OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var">is_flag</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OverlapFlag
</span><a href="#local-6989586621680916019"><span class="hs-identifier hs-var">oflag</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_dfun :: DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var">is_dfun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916020"><span class="hs-identifier hs-var">dfun</span></a></span><span>
</span><span id="line-268"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tvs :: [DFunId]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680916018"><span class="hs-identifier hs-var">tvs</span></a></span><span>
</span><span id="line-269"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_dfun_name :: Name
</span><a href="GHC.Core.InstEnv.html#is_dfun_name"><span class="hs-identifier hs-var">is_dfun_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916015"><span class="hs-identifier hs-var">dfun_name</span></a></span><span>
</span><span id="line-270"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_cls :: Class
</span><a href="GHC.Core.InstEnv.html#is_cls"><span class="hs-identifier hs-var">is_cls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680916017"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916014"><span class="hs-identifier hs-var">cls_name</span></a></span><span>
</span><span id="line-271"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916016"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Maybe Name]
</span><a href="GHC.Core.Unify.html#roughMatchTcs"><span class="hs-identifier hs-var">roughMatchTcs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916016"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-272"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_orphan :: IsOrphan
</span><a href="GHC.Core.InstEnv.html#is_orphan"><span class="hs-identifier hs-var">is_orphan</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><a href="#local-6989586621680916013"><span class="hs-identifier hs-var">orph</span></a></span><span>
</span><span id="line-273"></span><span>            </span><span class="hs-special">}</span><span>
</span><span id="line-274"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-275"></span><span>    </span><span id="local-6989586621680916014"><span class="annot"><span class="annottext">cls_name :: Name
</span><a href="#local-6989586621680916014"><span class="hs-identifier hs-var hs-var">cls_name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; Name
</span><a href="GHC.Core.Class.html#className"><span class="hs-identifier hs-var hs-var">className</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680916017"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-276"></span><span>    </span><span id="local-6989586621680916015"><span class="annot"><span class="annottext">dfun_name :: Name
</span><a href="#local-6989586621680916015"><span class="hs-identifier hs-var hs-var">dfun_name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; Name
</span><a href="GHC.Types.Id.html#idName"><span class="hs-identifier hs-var">idName</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680916020"><span class="hs-identifier hs-var">dfun</span></a></span><span>
</span><span id="line-277"></span><span>    </span><span id="local-6989586621680916008"><span class="annot"><span class="annottext">this_mod :: Module
</span><a href="#local-6989586621680916008"><span class="hs-identifier hs-var hs-var">this_mod</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">isExternalName</span><span> </span><span class="hs-identifier">dfun_name</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-identifier">nameModule</span><span> </span><span class="hs-identifier">dfun_name</span><span>
</span><span id="line-278"></span><span>    </span><span id="local-6989586621680916001"><span class="annot"><span class="annottext">is_local :: Name -&gt; Bool
</span><a href="#local-6989586621680916001"><span class="hs-identifier hs-var hs-var">is_local</span></a></span></span><span> </span><span id="local-6989586621680916000"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916000"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Module -&gt; Name -&gt; Bool
</span><a href="GHC.Types.Name.html#nameIsLocalOrFrom"><span class="hs-identifier hs-var">nameIsLocalOrFrom</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680916008"><span class="hs-identifier hs-var">this_mod</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916000"><span class="hs-identifier hs-var">name</span></a></span><span>
</span><span id="line-279"></span><span>
</span><span id="line-280"></span><span>        </span><span class="hs-comment">-- Compute orphanhood.  See Note [Orphans] in GHC.Core.InstEnv</span><span>
</span><span id="line-281"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680915998"><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915998"><span class="hs-identifier hs-var">cls_tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915997"><span class="annot"><span class="annottext">[FunDep DFunId]
</span><a href="#local-6989586621680915997"><span class="hs-identifier hs-var">fds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class -&gt; ([DFunId], [FunDep DFunId])
</span><a href="GHC.Core.Class.html#classTvsFds"><span class="hs-identifier hs-var">classTvsFds</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680916017"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-282"></span><span>    </span><span id="local-6989586621680915995"><span class="annot"><span class="annottext">arg_names :: [NameSet]
</span><a href="#local-6989586621680915995"><span class="hs-identifier hs-var hs-var">arg_names</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">(Name -&gt; Bool) -&gt; NameSet -&gt; NameSet
</span><a href="GHC.Types.Name.Set.html#filterNameSet"><span class="hs-identifier hs-var">filterNameSet</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; Bool
</span><a href="#local-6989586621680916001"><span class="hs-identifier hs-var">is_local</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Type -&gt; NameSet
</span><a href="GHC.Core.FVs.html#orphNamesOfType"><span class="hs-identifier hs-var">orphNamesOfType</span></a></span><span> </span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680915992"><span class="hs-identifier hs-var">ty</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621680915992"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680915992"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680916016"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-283"></span><span>
</span><span id="line-284"></span><span>    </span><span class="hs-comment">-- See Note [When exactly is an instance decl an orphan?]</span><span>
</span><span id="line-285"></span><span>    </span><span id="local-6989586621680916013"><span class="annot"><span class="annottext">orph :: IsOrphan
</span><a href="#local-6989586621680916013"><span class="hs-identifier hs-var hs-var">orph</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Bool
</span><a href="#local-6989586621680916001"><span class="hs-identifier hs-var">is_local</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916014"><span class="hs-identifier hs-var">cls_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OccName -&gt; IsOrphan
</span><a href="GHC.Core.html#NotOrphan"><span class="hs-identifier hs-var">NotOrphan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Name -&gt; OccName
</span><a href="GHC.Types.Name.html#nameOccName"><span class="hs-identifier hs-var">nameOccName</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680916014"><span class="hs-identifier hs-var">cls_name</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-286"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">(IsOrphan -&gt; Bool) -&gt; [IsOrphan] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#all"><span class="hs-identifier hs-var">all</span></a></span><span> </span><span class="annot"><span class="annottext">IsOrphan -&gt; Bool
</span><a href="#local-6989586621680915986"><span class="hs-identifier hs-var">notOrphan</span></a></span><span> </span><span class="annot"><span class="annottext">[IsOrphan]
</span><a href="#local-6989586621680915985"><span class="hs-identifier hs-var">mb_ns</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">not</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">null</span><span> </span><span class="hs-identifier">mb_ns</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-identifier">head</span><span> </span><span class="hs-identifier">mb_ns</span><span>
</span><span id="line-287"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><a href="GHC.Core.html#IsOrphan"><span class="hs-identifier hs-var">IsOrphan</span></a></span><span>
</span><span id="line-288"></span><span>
</span><span id="line-289"></span><span>    </span><span id="local-6989586621680915986"><span class="annot"><span class="annottext">notOrphan :: IsOrphan -&gt; Bool
</span><a href="#local-6989586621680915986"><span class="hs-identifier hs-var hs-var">notOrphan</span></a></span></span><span> </span><span class="annot"><a href="GHC.Core.html#NotOrphan"><span class="hs-identifier hs-type">NotOrphan</span></a></span><span class="hs-special">{</span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-290"></span><span>    </span><span class="annot"><a href="#local-6989586621680915986"><span class="hs-identifier hs-var">notOrphan</span></a></span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-291"></span><span>
</span><span id="line-292"></span><span>    </span><span class="annot"><a href="#local-6989586621680915985"><span class="hs-identifier hs-type">mb_ns</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.html#IsOrphan"><span class="hs-identifier hs-type">IsOrphan</span></a></span><span class="hs-special">]</span><span>    </span><span class="hs-comment">-- One for each fundep; a locally-defined name</span><span>
</span><span id="line-293"></span><span>                           </span><span class="hs-comment">-- that is not in the &quot;determined&quot; arguments</span><span>
</span><span id="line-294"></span><span>    </span><span id="local-6989586621680915985"><span class="annot"><span class="annottext">mb_ns :: [IsOrphan]
</span><a href="#local-6989586621680915985"><span class="hs-identifier hs-var hs-var">mb_ns</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[FunDep DFunId] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[FunDep DFunId]
</span><a href="#local-6989586621680915997"><span class="hs-identifier hs-var">fds</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">[NameSet] -&gt; IsOrphan
</span><a href="#local-6989586621680915981"><span class="hs-identifier hs-var">choose_one</span></a></span><span> </span><span class="annot"><span class="annottext">[NameSet]
</span><a href="#local-6989586621680915995"><span class="hs-identifier hs-var">arg_names</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-295"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(FunDep DFunId -&gt; IsOrphan) -&gt; [FunDep DFunId] -&gt; [IsOrphan]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">FunDep DFunId -&gt; IsOrphan
forall {t :: * -&gt; *} {a}. Foldable t =&gt; (a, t DFunId) -&gt; IsOrphan
</span><a href="#local-6989586621680915980"><span class="hs-identifier hs-var">do_one</span></a></span><span> </span><span class="annot"><span class="annottext">[FunDep DFunId]
</span><a href="#local-6989586621680915997"><span class="hs-identifier hs-var">fds</span></a></span><span>
</span><span id="line-296"></span><span>    </span><span id="local-6989586621680915980"><span class="annot"><span class="annottext">do_one :: (a, t DFunId) -&gt; IsOrphan
</span><a href="#local-6989586621680915980"><span class="hs-identifier hs-var hs-var">do_one</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915975"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680915975"><span class="hs-identifier hs-var">_ltvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915974"><span class="annot"><span class="annottext">t DFunId
</span><a href="#local-6989586621680915974"><span class="hs-identifier hs-var">rtvs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[NameSet] -&gt; IsOrphan
</span><a href="#local-6989586621680915981"><span class="hs-identifier hs-var">choose_one</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">NameSet
</span><a href="#local-6989586621680915973"><span class="hs-identifier hs-var">ns</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915972"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915972"><span class="hs-identifier hs-var">tv</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680915973"><span class="annot"><span class="annottext">NameSet
</span><a href="#local-6989586621680915973"><span class="hs-identifier hs-var">ns</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915998"><span class="hs-identifier hs-var">cls_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[DFunId] -&gt; [NameSet] -&gt; [(DFunId, NameSet)]
forall a b. [a] -&gt; [b] -&gt; [(a, b)]
</span><a href="../../base/src/GHC.List.html#zip"><span class="hs-operator hs-var">`zip`</span></a></span><span> </span><span class="annot"><span class="annottext">[NameSet]
</span><a href="#local-6989586621680915995"><span class="hs-identifier hs-var">arg_names</span></a></span><span>
</span><span id="line-297"></span><span>                                            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915972"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; t DFunId -&gt; Bool
forall (t :: * -&gt; *) a. (Foldable t, Eq a) =&gt; a -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#elem"><span class="hs-operator hs-var">`elem`</span></a></span><span> </span><span class="annot"><span class="annottext">t DFunId
</span><a href="#local-6989586621680915974"><span class="hs-identifier hs-var">rtvs</span></a></span><span class="hs-special">)</span><span class="hs-special">]</span><span>
</span><span id="line-298"></span><span>
</span><span id="line-299"></span><span>    </span><span id="local-6989586621680915981"><span class="annot"><span class="annottext">choose_one :: [NameSet] -&gt; IsOrphan
</span><a href="#local-6989586621680915981"><span class="hs-identifier hs-var hs-var">choose_one</span></a></span></span><span> </span><span id="local-6989586621680915970"><span class="annot"><span class="annottext">[NameSet]
</span><a href="#local-6989586621680915970"><span class="hs-identifier hs-var">nss</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NameSet -&gt; IsOrphan
</span><a href="GHC.Core.html#chooseOrphanAnchor"><span class="hs-identifier hs-var">chooseOrphanAnchor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[NameSet] -&gt; NameSet
</span><a href="GHC.Types.Name.Set.html#unionNameSets"><span class="hs-identifier hs-var">unionNameSets</span></a></span><span> </span><span class="annot"><span class="annottext">[NameSet]
</span><a href="#local-6989586621680915970"><span class="hs-identifier hs-var">nss</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-300"></span><span>
</span><span id="line-301"></span><span class="annot"><a href="GHC.Core.InstEnv.html#mkImportedInstance"><span class="hs-identifier hs-type">mkImportedInstance</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span>         </span><span class="hs-comment">-- ^ the name of the class</span><span>
</span><span id="line-302"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-comment">-- ^ the types which the class was applied to</span><span>
</span><span id="line-303"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Name.html#Name"><span class="hs-identifier hs-type">Name</span></a></span><span>         </span><span class="hs-comment">-- ^ the 'Name' of the dictionary binding</span><span>
</span><span id="line-304"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span>       </span><span class="hs-comment">-- ^ the 'Id' of the dictionary.</span><span>
</span><span id="line-305"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#OverlapFlag"><span class="hs-identifier hs-type">OverlapFlag</span></a></span><span>  </span><span class="hs-comment">-- ^ may this instance overlap?</span><span>
</span><span id="line-306"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.html#IsOrphan"><span class="hs-identifier hs-type">IsOrphan</span></a></span><span>     </span><span class="hs-comment">-- ^ is this instance an orphan?</span><span>
</span><span id="line-307"></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span>
</span><span id="line-308"></span><span class="hs-comment">-- Used for imported instances, where we get the rough-match stuff</span><span>
</span><span id="line-309"></span><span class="hs-comment">-- from the interface file</span><span>
</span><span id="line-310"></span><span class="hs-comment">-- The bound tyvars of the dfun are guaranteed fresh, because</span><span>
</span><span id="line-311"></span><span class="hs-comment">-- the dfun has been typechecked out of the same interface file</span><span>
</span><span id="line-312"></span><span id="mkImportedInstance"><span class="annot"><span class="annottext">mkImportedInstance :: Name
-&gt; [Maybe Name]
-&gt; Name
-&gt; DFunId
-&gt; OverlapFlag
-&gt; IsOrphan
-&gt; ClsInst
</span><a href="GHC.Core.InstEnv.html#mkImportedInstance"><span class="hs-identifier hs-var hs-var">mkImportedInstance</span></a></span></span><span> </span><span id="local-6989586621680915968"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915968"><span class="hs-identifier hs-var">cls_nm</span></a></span></span><span> </span><span id="local-6989586621680915967"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915967"><span class="hs-identifier hs-var">mb_tcs</span></a></span></span><span> </span><span id="local-6989586621680915966"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915966"><span class="hs-identifier hs-var">dfun_name</span></a></span></span><span> </span><span id="local-6989586621680915965"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915965"><span class="hs-identifier hs-var">dfun</span></a></span></span><span> </span><span id="local-6989586621680915964"><span class="annot"><span class="annottext">OverlapFlag
</span><a href="#local-6989586621680915964"><span class="hs-identifier hs-var">oflag</span></a></span></span><span> </span><span id="local-6989586621680915963"><span class="annot"><span class="annottext">IsOrphan
</span><a href="#local-6989586621680915963"><span class="hs-identifier hs-var">orphan</span></a></span></span><span>
</span><span id="line-313"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst :: Name
-&gt; [Maybe Name]
-&gt; Name
-&gt; [DFunId]
-&gt; Class
-&gt; [Type]
-&gt; DFunId
-&gt; OverlapFlag
-&gt; IsOrphan
-&gt; ClsInst
</span><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_flag :: OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var">is_flag</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OverlapFlag
</span><a href="#local-6989586621680915964"><span class="hs-identifier hs-var">oflag</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_dfun :: DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var">is_dfun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915965"><span class="hs-identifier hs-var">dfun</span></a></span><span>
</span><span id="line-314"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tvs :: [DFunId]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915962"><span class="hs-identifier hs-var">tvs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915961"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-315"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_dfun_name :: Name
</span><a href="GHC.Core.InstEnv.html#is_dfun_name"><span class="hs-identifier hs-var">is_dfun_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915966"><span class="hs-identifier hs-var">dfun_name</span></a></span><span>
</span><span id="line-316"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915968"><span class="hs-identifier hs-var">cls_nm</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_cls :: Class
</span><a href="GHC.Core.InstEnv.html#is_cls"><span class="hs-identifier hs-var">is_cls</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915960"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915967"><span class="hs-identifier hs-var">mb_tcs</span></a></span><span>
</span><span id="line-317"></span><span>            </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_orphan :: IsOrphan
</span><a href="GHC.Core.InstEnv.html#is_orphan"><span class="hs-identifier hs-var">is_orphan</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><a href="#local-6989586621680915963"><span class="hs-identifier hs-var">orphan</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-318"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-319"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680915962"><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915962"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915960"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915960"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915961"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915961"><span class="hs-identifier hs-var">tys</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; ([DFunId], [Type], Class, [Type])
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitDFunTy"><span class="hs-identifier hs-var">tcSplitDFunTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915965"><span class="hs-identifier hs-var">dfun</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-320"></span><span>
</span><span id="line-321"></span><span class="hs-comment">{-
Note [When exactly is an instance decl an orphan?]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (see GHC.Iface.Make.instanceToIfaceInst, which implements this)
Roughly speaking, an instance is an orphan if its head (after the =&gt;)
mentions nothing defined in this module.

Functional dependencies complicate the situation though. Consider

  module M where { class C a b | a -&gt; b }

and suppose we are compiling module X:

  module X where
        import M
        data T = ...
        instance C Int T where ...

This instance is an orphan, because when compiling a third module Y we
might get a constraint (C Int v), and we'd want to improve v to T.  So
we must make sure X's instances are loaded, even if we do not directly
use anything from X.

More precisely, an instance is an orphan iff

  If there are no fundeps, then at least of the names in
  the instance head is locally defined.

  If there are fundeps, then for every fundep, at least one of the
  names free in a *non-determined* part of the instance head is
  defined in this module.

(Note that these conditions hold trivially if the class is locally
defined.)


************************************************************************
*                                                                      *
                InstEnv, ClsInstEnv
*                                                                      *
************************************************************************

A @ClsInstEnv@ all the instances of that class.  The @Id@ inside a
ClsInstEnv mapping is the dfun for that instance.

If class C maps to a list containing the item ([a,b], [t1,t2,t3], dfun), then

        forall a b, C t1 t2 t3  can be constructed by dfun

or, to put it another way, we have

        instance (...) =&gt; C t1 t2 t3,  witnessed by dfun
-}</span><span>
</span><span id="line-374"></span><span>
</span><span id="line-375"></span><span class="hs-comment">---------------------------------------------------</span><span>
</span><span id="line-376"></span><span class="hs-comment">{-
Note [InstEnv determinism]
~~~~~~~~~~~~~~~~~~~~~~~~~~
We turn InstEnvs into a list in some places that don't directly affect
the ABI. That happens when we create output for `:info`.
Unfortunately that nondeterminism is nonlocal and it's hard to tell what it
affects without following a chain of functions. It's also easy to accidentally
make that nondeterminism affect the ABI. Furthermore the envs should be
relatively small, so it should be free to use deterministic maps here.
Testing with nofib and validate detected no difference between UniqFM and
UniqDFM. See also Note [Deterministic UniqFM]
-}</span><span>
</span><span id="line-388"></span><span>
</span><span id="line-389"></span><span class="hs-comment">-- Internally it's safe to indexable this map by</span><span>
</span><span id="line-390"></span><span class="hs-comment">-- by @Class@, the classes @Name@, the classes @TyCon@</span><span>
</span><span id="line-391"></span><span class="hs-comment">-- or it's @Unique@.</span><span>
</span><span id="line-392"></span><span class="hs-comment">-- This is since:</span><span>
</span><span id="line-393"></span><span class="hs-comment">-- getUnique cls == getUnique (className cls) == getUnique (classTyCon cls)</span><span>
</span><span id="line-394"></span><span class="hs-comment">--</span><span>
</span><span id="line-395"></span><span class="hs-comment">-- We still use Class as key type as it's both the common case</span><span>
</span><span id="line-396"></span><span class="hs-comment">-- and conveys the meaning better. But the implementation of</span><span>
</span><span id="line-397"></span><span class="hs-comment">--InstEnv is a bit more lax internally.</span><span>
</span><span id="line-398"></span><span class="hs-keyword">type</span><span> </span><span id="InstEnv"><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-var">InstEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Types.Unique.DFM.html#UniqDFM"><span class="hs-identifier hs-type">UniqDFM</span></a></span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInstEnv"><span class="hs-identifier hs-type">ClsInstEnv</span></a></span><span>      </span><span class="hs-comment">-- Maps Class to instances for that class</span><span>
</span><span id="line-399"></span><span>  </span><span class="hs-comment">-- See Note [InstEnv determinism]</span><span>
</span><span id="line-400"></span><span>
</span><span id="line-401"></span><span class="hs-comment">-- | 'InstEnvs' represents the combination of the global type class instance</span><span>
</span><span id="line-402"></span><span class="hs-comment">-- environment, the local type class instance environment, and the set of</span><span>
</span><span id="line-403"></span><span class="hs-comment">-- transitively reachable orphan modules (according to what modules have been</span><span>
</span><span id="line-404"></span><span class="hs-comment">-- directly imported) used to test orphan instance visibility.</span><span>
</span><span id="line-405"></span><span class="hs-keyword">data</span><span> </span><span id="InstEnvs"><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-var">InstEnvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="InstEnvs"><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-var">InstEnvs</span></a></span></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-406"></span><span>        </span><span id="ie_global"><span class="annot"><span class="annottext">InstEnvs -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#ie_global"><span class="hs-identifier hs-var hs-var">ie_global</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span class="hs-special">,</span><span>               </span><span class="hs-comment">-- External-package instances</span><span>
</span><span id="line-407"></span><span>        </span><span id="ie_local"><span class="annot"><span class="annottext">InstEnvs -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#ie_local"><span class="hs-identifier hs-var hs-var">ie_local</span></a></span></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span class="hs-special">,</span><span>               </span><span class="hs-comment">-- Home-package instances</span><span>
</span><span id="line-408"></span><span>        </span><span id="ie_visible"><span class="annot"><span class="annottext">InstEnvs -&gt; VisibleOrphanModules
</span><a href="GHC.Core.InstEnv.html#ie_visible"><span class="hs-identifier hs-var hs-var">ie_visible</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#VisibleOrphanModules"><span class="hs-identifier hs-type">VisibleOrphanModules</span></a></span><span>   </span><span class="hs-comment">-- Set of all orphan modules transitively</span><span>
</span><span id="line-409"></span><span>                                             </span><span class="hs-comment">-- reachable from the module being compiled</span><span>
</span><span id="line-410"></span><span>                                             </span><span class="hs-comment">-- See Note [Instance lookup and orphan instances]</span><span>
</span><span id="line-411"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-412"></span><span>
</span><span id="line-413"></span><span class="hs-comment">-- | Set of visible orphan modules, according to what modules have been directly</span><span>
</span><span id="line-414"></span><span class="hs-comment">-- imported.  This is based off of the dep_orphs field, which records</span><span>
</span><span id="line-415"></span><span class="hs-comment">-- transitively reachable orphan modules (modules that define orphan instances).</span><span>
</span><span id="line-416"></span><span class="hs-keyword">type</span><span> </span><span id="VisibleOrphanModules"><span class="annot"><a href="GHC.Core.InstEnv.html#VisibleOrphanModules"><span class="hs-identifier hs-var">VisibleOrphanModules</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.Unit.Module.Env.html#ModuleSet"><span class="hs-identifier hs-type">ModuleSet</span></a></span><span>
</span><span id="line-417"></span><span>
</span><span id="line-418"></span><span class="hs-keyword">newtype</span><span> </span><span id="ClsInstEnv"><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInstEnv"><span class="hs-identifier hs-var">ClsInstEnv</span></a></span></span><span>
</span><span id="line-419"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="ClsIE"><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-var">ClsIE</span></a></span></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span>    </span><span class="hs-comment">-- The instances for a particular class, in any order</span><span>
</span><span id="line-420"></span><span>
</span><span id="line-421"></span><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680915951"><span class="annot"><a href="GHC.Utils.Outputable.html#Outputable"><span class="hs-identifier hs-type">Outputable</span></a></span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInstEnv"><span class="hs-identifier hs-type">ClsInstEnv</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-422"></span><span>  </span><span id="local-6989586621680915950"><span class="annot"><span class="annottext">ppr :: ClsInstEnv -&gt; SDoc
</span><a href="#local-6989586621680915950"><span class="hs-identifier hs-var hs-var hs-var hs-var">ppr</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915949"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915949"><span class="hs-identifier hs-var">is</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ClsInst] -&gt; SDoc
</span><a href="GHC.Core.InstEnv.html#pprInstances"><span class="hs-identifier hs-var">pprInstances</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915949"><span class="hs-identifier hs-var">is</span></a></span><span>
</span><span id="line-423"></span><span>
</span><span id="line-424"></span><span class="hs-comment">-- INVARIANTS:</span><span>
</span><span id="line-425"></span><span class="hs-comment">--  * The is_tvs are distinct in each ClsInst</span><span>
</span><span id="line-426"></span><span class="hs-comment">--      of a ClsInstEnv (so we can safely unify them)</span><span>
</span><span id="line-427"></span><span>
</span><span id="line-428"></span><span class="hs-comment">-- Thus, the @ClassInstEnv@ for @Eq@ might contain the following entry:</span><span>
</span><span id="line-429"></span><span class="hs-comment">--      [a] ===&gt; dfun_Eq_List :: forall a. Eq a =&gt; Eq [a]</span><span>
</span><span id="line-430"></span><span class="hs-comment">-- The &quot;a&quot; in the pattern must be one of the forall'd variables in</span><span>
</span><span id="line-431"></span><span class="hs-comment">-- the dfun type.</span><span>
</span><span id="line-432"></span><span>
</span><span id="line-433"></span><span class="annot"><a href="GHC.Core.InstEnv.html#emptyInstEnv"><span class="hs-identifier hs-type">emptyInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span>
</span><span id="line-434"></span><span id="emptyInstEnv"><span class="annot"><span class="annottext">emptyInstEnv :: InstEnv
</span><a href="GHC.Core.InstEnv.html#emptyInstEnv"><span class="hs-identifier hs-var hs-var">emptyInstEnv</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnv
forall key elt. UniqDFM key elt
</span><a href="GHC.Types.Unique.DFM.html#emptyUDFM"><span class="hs-identifier hs-var">emptyUDFM</span></a></span><span>
</span><span id="line-435"></span><span>
</span><span id="line-436"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instEnvElts"><span class="hs-identifier hs-type">instEnvElts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-437"></span><span id="instEnvElts"><span class="annot"><span class="annottext">instEnvElts :: InstEnv -&gt; [ClsInst]
</span><a href="GHC.Core.InstEnv.html#instEnvElts"><span class="hs-identifier hs-var hs-var">instEnvElts</span></a></span></span><span> </span><span id="local-6989586621680915947"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915947"><span class="hs-identifier hs-var">ie</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915946"><span class="hs-identifier hs-var">elt</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915945"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915945"><span class="hs-identifier hs-var">elts</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; [ClsInstEnv]
forall key elt. UniqDFM key elt -&gt; [elt]
</span><a href="GHC.Types.Unique.DFM.html#eltsUDFM"><span class="hs-identifier hs-var">eltsUDFM</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915947"><span class="hs-identifier hs-var">ie</span></a></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915946"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915946"><span class="hs-identifier hs-var">elt</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915945"><span class="hs-identifier hs-var">elts</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-438"></span><span>  </span><span class="hs-comment">-- See Note [InstEnv determinism]</span><span>
</span><span id="line-439"></span><span>
</span><span id="line-440"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instEnvClasses"><span class="hs-identifier hs-type">instEnvClasses</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-441"></span><span id="instEnvClasses"><span class="annot"><span class="annottext">instEnvClasses :: InstEnv -&gt; [Class]
</span><a href="GHC.Core.InstEnv.html#instEnvClasses"><span class="hs-identifier hs-var hs-var">instEnvClasses</span></a></span></span><span> </span><span id="local-6989586621680915943"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915943"><span class="hs-identifier hs-var">ie</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">ClsInst -&gt; Class
</span><a href="GHC.Core.InstEnv.html#is_cls"><span class="hs-identifier hs-var hs-var">is_cls</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915942"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915942"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915942"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; [ClsInstEnv]
forall key elt. UniqDFM key elt -&gt; [elt]
</span><a href="GHC.Types.Unique.DFM.html#eltsUDFM"><span class="hs-identifier hs-var">eltsUDFM</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915943"><span class="hs-identifier hs-var">ie</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-442"></span><span>
</span><span id="line-443"></span><span class="hs-comment">-- | Test if an instance is visible, by checking that its origin module</span><span>
</span><span id="line-444"></span><span class="hs-comment">-- is in 'VisibleOrphanModules'.</span><span>
</span><span id="line-445"></span><span class="hs-comment">-- See Note [Instance lookup and orphan instances]</span><span>
</span><span id="line-446"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instIsVisible"><span class="hs-identifier hs-type">instIsVisible</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#VisibleOrphanModules"><span class="hs-identifier hs-type">VisibleOrphanModules</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-447"></span><span id="instIsVisible"><span class="annot"><span class="annottext">instIsVisible :: VisibleOrphanModules -&gt; ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#instIsVisible"><span class="hs-identifier hs-var hs-var">instIsVisible</span></a></span></span><span> </span><span id="local-6989586621680915941"><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915941"><span class="hs-identifier hs-var">vis_mods</span></a></span></span><span> </span><span id="local-6989586621680915940"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915940"><span class="hs-identifier hs-var">ispec</span></a></span></span><span>
</span><span id="line-448"></span><span>  </span><span class="hs-comment">-- NB: Instances from the interactive package always are visible. We can't</span><span>
</span><span id="line-449"></span><span>  </span><span class="hs-comment">-- add interactive modules to the set since we keep creating new ones</span><span>
</span><span id="line-450"></span><span>  </span><span class="hs-comment">-- as a GHCi session progresses.</span><span>
</span><span id="line-451"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Maybe Module
</span><a href="GHC.Types.Name.html#nameModule_maybe"><span class="hs-identifier hs-var">nameModule_maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_dfun_name"><span class="hs-identifier hs-var hs-var">is_dfun_name</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915940"><span class="hs-identifier hs-var">ispec</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-452"></span><span>      </span><span class="annot"><span class="annottext">Maybe Module
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-453"></span><span>      </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680915938"><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680915938"><span class="hs-identifier hs-var">mod</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Module -&gt; Bool
</span><a href="GHC.Unit.Types.html#isInteractiveModule"><span class="hs-identifier hs-var">isInteractiveModule</span></a></span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680915938"><span class="hs-identifier hs-var">mod</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-454"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">IsOrphan
</span><a href="GHC.Core.html#IsOrphan"><span class="hs-identifier hs-var">IsOrphan</span></a></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; IsOrphan
</span><a href="GHC.Core.InstEnv.html#is_orphan"><span class="hs-identifier hs-var hs-var">is_orphan</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915940"><span class="hs-identifier hs-var">ispec</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Module
</span><a href="#local-6989586621680915938"><span class="hs-identifier hs-var">mod</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; VisibleOrphanModules -&gt; Bool
</span><a href="GHC.Unit.Module.Env.html#elemModuleSet"><span class="hs-operator hs-var">`elemModuleSet`</span></a></span><span> </span><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915941"><span class="hs-identifier hs-var">vis_mods</span></a></span><span>
</span><span id="line-455"></span><span>               </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span class="annot"><a href="GHC.Core.InstEnv.html#classInstances"><span class="hs-identifier hs-type">classInstances</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-458"></span><span id="classInstances"><span class="annot"><span class="annottext">classInstances :: InstEnvs -&gt; Class -&gt; [ClsInst]
</span><a href="GHC.Core.InstEnv.html#classInstances"><span class="hs-identifier hs-var hs-var">classInstances</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ie_global :: InstEnvs -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#ie_global"><span class="hs-identifier hs-var">ie_global</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915935"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915935"><span class="hs-identifier hs-var">pkg_ie</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ie_local :: InstEnvs -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#ie_local"><span class="hs-identifier hs-var">ie_local</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915934"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915934"><span class="hs-identifier hs-var">home_ie</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ie_visible :: InstEnvs -&gt; VisibleOrphanModules
</span><a href="GHC.Core.InstEnv.html#ie_visible"><span class="hs-identifier hs-var">ie_visible</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915933"><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915933"><span class="hs-identifier hs-var">vis_mods</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span id="local-6989586621680915932"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915932"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-459"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; [ClsInst]
</span><a href="#local-6989586621680915931"><span class="hs-identifier hs-var">get</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915934"><span class="hs-identifier hs-var">home_ie</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst] -&gt; [ClsInst] -&gt; [ClsInst]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; [ClsInst]
</span><a href="#local-6989586621680915931"><span class="hs-identifier hs-var">get</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915935"><span class="hs-identifier hs-var">pkg_ie</span></a></span><span>
</span><span id="line-460"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-461"></span><span>    </span><span id="local-6989586621680915931"><span class="annot"><span class="annottext">get :: InstEnv -&gt; [ClsInst]
</span><a href="#local-6989586621680915931"><span class="hs-identifier hs-var hs-var">get</span></a></span></span><span> </span><span id="local-6989586621680915929"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915929"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; Class -&gt; Maybe ClsInstEnv
forall key elt.
Uniquable key =&gt;
UniqDFM key elt -&gt; key -&gt; Maybe elt
</span><a href="GHC.Types.Unique.DFM.html#lookupUDFM"><span class="hs-identifier hs-var">lookupUDFM</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915929"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915932"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-462"></span><span>                </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915927"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915927"><span class="hs-identifier hs-var">insts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(ClsInst -&gt; Bool) -&gt; [ClsInst] -&gt; [ClsInst]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#filter"><span class="hs-identifier hs-var">filter</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VisibleOrphanModules -&gt; ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#instIsVisible"><span class="hs-identifier hs-var">instIsVisible</span></a></span><span> </span><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915933"><span class="hs-identifier hs-var">vis_mods</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915927"><span class="hs-identifier hs-var">insts</span></a></span><span>
</span><span id="line-463"></span><span>                </span><span class="annot"><span class="annottext">Maybe ClsInstEnv
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-464"></span><span>
</span><span id="line-465"></span><span class="hs-comment">-- | Checks for an exact match of ClsInst in the instance environment.</span><span>
</span><span id="line-466"></span><span class="hs-comment">-- We use this when we do signature checking in &quot;GHC.Tc.Module&quot;</span><span>
</span><span id="line-467"></span><span class="annot"><a href="GHC.Core.InstEnv.html#memberInstEnv"><span class="hs-identifier hs-type">memberInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-468"></span><span id="memberInstEnv"><span class="annot"><span class="annottext">memberInstEnv :: InstEnv -&gt; ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#memberInstEnv"><span class="hs-identifier hs-var hs-var">memberInstEnv</span></a></span></span><span> </span><span id="local-6989586621680915926"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915926"><span class="hs-identifier hs-var">inst_env</span></a></span></span><span> </span><span id="local-6989586621680915925"><span class="annot"><span class="annottext">ins_item :: ClsInst
</span><a href="#local-6989586621680915925"><span class="hs-identifier hs-var">ins_item</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915924"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915924"><span class="hs-identifier hs-var">cls_nm</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-469"></span><span>    </span><span class="annot"><span class="annottext">Bool -&gt; (ClsInstEnv -&gt; Bool) -&gt; Maybe ClsInstEnv -&gt; Bool
forall b a. b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
</span><a href="../../base/src/Data.Maybe.html#maybe"><span class="hs-identifier hs-var">maybe</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915922"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915922"><span class="hs-identifier hs-var">items</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(ClsInst -&gt; Bool) -&gt; [ClsInst] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#any"><span class="hs-identifier hs-var">any</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915920"><span class="hs-identifier hs-var">identicalDFunType</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915925"><span class="hs-identifier hs-var">ins_item</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915922"><span class="hs-identifier hs-var">items</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-470"></span><span>          </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InstEnv -&gt; Unique -&gt; Maybe ClsInstEnv
forall key elt. UniqDFM key elt -&gt; Unique -&gt; Maybe elt
</span><a href="GHC.Types.Unique.DFM.html#lookupUDFM_Directly"><span class="hs-identifier hs-var">lookupUDFM_Directly</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915926"><span class="hs-identifier hs-var">inst_env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Name -&gt; Unique
forall a. Uniquable a =&gt; a -&gt; Unique
</span><a href="GHC.Types.Unique.html#getUnique"><span class="hs-identifier hs-var">getUnique</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915924"><span class="hs-identifier hs-var">cls_nm</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-471"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-472"></span><span>  </span><span id="local-6989586621680915920"><span class="annot"><span class="annottext">identicalDFunType :: ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915920"><span class="hs-identifier hs-var hs-var">identicalDFunType</span></a></span></span><span> </span><span id="local-6989586621680915918"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915918"><span class="hs-identifier hs-var">cls1</span></a></span></span><span> </span><span id="local-6989586621680915917"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915917"><span class="hs-identifier hs-var">cls2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-473"></span><span>    </span><span class="annot"><span class="annottext">Type -&gt; Type -&gt; Bool
</span><a href="GHC.Core.Type.html#eqType"><span class="hs-identifier hs-var">eqType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Var.html#varType"><span class="hs-identifier hs-var hs-var">varType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915918"><span class="hs-identifier hs-var">cls1</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Var.html#varType"><span class="hs-identifier hs-var hs-var">varType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var hs-var">is_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915917"><span class="hs-identifier hs-var">cls2</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-474"></span><span>
</span><span id="line-475"></span><span class="annot"><a href="GHC.Core.InstEnv.html#extendInstEnvList"><span class="hs-identifier hs-type">extendInstEnvList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span>
</span><span id="line-476"></span><span id="extendInstEnvList"><span class="annot"><span class="annottext">extendInstEnvList :: InstEnv -&gt; [ClsInst] -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#extendInstEnvList"><span class="hs-identifier hs-var hs-var">extendInstEnvList</span></a></span></span><span> </span><span id="local-6989586621680915914"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915914"><span class="hs-identifier hs-var">inst_env</span></a></span></span><span> </span><span id="local-6989586621680915913"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915913"><span class="hs-identifier hs-var">ispecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(InstEnv -&gt; ClsInst -&gt; InstEnv) -&gt; InstEnv -&gt; [ClsInst] -&gt; InstEnv
forall (t :: * -&gt; *) b a.
Foldable t =&gt;
(b -&gt; a -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldl%27"><span class="hs-identifier hs-var">foldl'</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; ClsInst -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#extendInstEnv"><span class="hs-identifier hs-var">extendInstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915914"><span class="hs-identifier hs-var">inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915913"><span class="hs-identifier hs-var">ispecs</span></a></span><span>
</span><span id="line-477"></span><span>
</span><span id="line-478"></span><span class="annot"><a href="GHC.Core.InstEnv.html#extendInstEnv"><span class="hs-identifier hs-type">extendInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span>
</span><span id="line-479"></span><span id="extendInstEnv"><span class="annot"><span class="annottext">extendInstEnv :: InstEnv -&gt; ClsInst -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#extendInstEnv"><span class="hs-identifier hs-var hs-var">extendInstEnv</span></a></span></span><span> </span><span id="local-6989586621680915911"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915911"><span class="hs-identifier hs-var">inst_env</span></a></span></span><span> </span><span id="local-6989586621680915910"><span class="annot"><span class="annottext">ins_item :: ClsInst
</span><a href="#local-6989586621680915910"><span class="hs-identifier hs-var">ins_item</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915909"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915909"><span class="hs-identifier hs-var">cls_nm</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-480"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ClsInstEnv -&gt; ClsInstEnv -&gt; ClsInstEnv)
-&gt; InstEnv -&gt; Unique -&gt; ClsInstEnv -&gt; InstEnv
forall elt key.
(elt -&gt; elt -&gt; elt)
-&gt; UniqDFM key elt -&gt; Unique -&gt; elt -&gt; UniqDFM key elt
</span><a href="GHC.Types.Unique.DFM.html#addToUDFM_C_Directly"><span class="hs-identifier hs-var">addToUDFM_C_Directly</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInstEnv -&gt; ClsInstEnv -&gt; ClsInstEnv
forall {p}. ClsInstEnv -&gt; p -&gt; ClsInstEnv
</span><a href="#local-6989586621680915907"><span class="hs-identifier hs-var">add</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915911"><span class="hs-identifier hs-var">inst_env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Name -&gt; Unique
forall a. Uniquable a =&gt; a -&gt; Unique
</span><a href="GHC.Types.Unique.html#getUnique"><span class="hs-identifier hs-var">getUnique</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915909"><span class="hs-identifier hs-var">cls_nm</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[ClsInst] -&gt; ClsInstEnv
</span><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-var">ClsIE</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915910"><span class="hs-identifier hs-var">ins_item</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-481"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-482"></span><span>    </span><span id="local-6989586621680915907"><span class="annot"><span class="annottext">add :: ClsInstEnv -&gt; p -&gt; ClsInstEnv
</span><a href="#local-6989586621680915907"><span class="hs-identifier hs-var hs-var">add</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915906"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915906"><span class="hs-identifier hs-var">cur_insts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">p
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ClsInst] -&gt; ClsInstEnv
</span><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-var">ClsIE</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915910"><span class="hs-identifier hs-var">ins_item</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; [ClsInst] -&gt; [ClsInst]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915906"><span class="hs-identifier hs-var">cur_insts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-483"></span><span>
</span><span id="line-484"></span><span class="annot"><a href="GHC.Core.InstEnv.html#deleteFromInstEnv"><span class="hs-identifier hs-type">deleteFromInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span>
</span><span id="line-485"></span><span id="deleteFromInstEnv"><span class="annot"><span class="annottext">deleteFromInstEnv :: InstEnv -&gt; ClsInst -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#deleteFromInstEnv"><span class="hs-identifier hs-var hs-var">deleteFromInstEnv</span></a></span></span><span> </span><span id="local-6989586621680915905"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915905"><span class="hs-identifier hs-var">inst_env</span></a></span></span><span> </span><span id="local-6989586621680915904"><span class="annot"><span class="annottext">ins_item :: ClsInst
</span><a href="#local-6989586621680915904"><span class="hs-identifier hs-var">ins_item</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915903"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915903"><span class="hs-identifier hs-var">cls_nm</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-486"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ClsInstEnv -&gt; ClsInstEnv) -&gt; InstEnv -&gt; Unique -&gt; InstEnv
forall elt key.
(elt -&gt; elt) -&gt; UniqDFM key elt -&gt; Unique -&gt; UniqDFM key elt
</span><a href="GHC.Types.Unique.DFM.html#adjustUDFM_Directly"><span class="hs-identifier hs-var">adjustUDFM_Directly</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInstEnv -&gt; ClsInstEnv
</span><a href="#local-6989586621680915901"><span class="hs-identifier hs-var">adjust</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915905"><span class="hs-identifier hs-var">inst_env</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Name -&gt; Unique
forall a. Uniquable a =&gt; a -&gt; Unique
</span><a href="GHC.Types.Unique.html#getUnique"><span class="hs-identifier hs-var">getUnique</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915903"><span class="hs-identifier hs-var">cls_nm</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-487"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-488"></span><span>    </span><span id="local-6989586621680915901"><span class="annot"><span class="annottext">adjust :: ClsInstEnv -&gt; ClsInstEnv
</span><a href="#local-6989586621680915901"><span class="hs-identifier hs-var hs-var">adjust</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915900"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915900"><span class="hs-identifier hs-var">items</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ClsInst] -&gt; ClsInstEnv
</span><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-var">ClsIE</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ClsInst -&gt; Bool) -&gt; [ClsInst] -&gt; [ClsInst]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#filterOut"><span class="hs-identifier hs-var">filterOut</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#identicalClsInstHead"><span class="hs-identifier hs-var">identicalClsInstHead</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915904"><span class="hs-identifier hs-var">ins_item</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915900"><span class="hs-identifier hs-var">items</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-489"></span><span>
</span><span id="line-490"></span><span class="annot"><a href="GHC.Core.InstEnv.html#deleteDFunFromInstEnv"><span class="hs-identifier hs-type">deleteDFunFromInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#DFunId"><span class="hs-identifier hs-type">DFunId</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span>
</span><span id="line-491"></span><span class="hs-comment">-- Delete a specific instance fron an InstEnv</span><span>
</span><span id="line-492"></span><span id="deleteDFunFromInstEnv"><span class="annot"><span class="annottext">deleteDFunFromInstEnv :: InstEnv -&gt; DFunId -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#deleteDFunFromInstEnv"><span class="hs-identifier hs-var hs-var">deleteDFunFromInstEnv</span></a></span></span><span> </span><span id="local-6989586621680915898"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915898"><span class="hs-identifier hs-var">inst_env</span></a></span></span><span> </span><span id="local-6989586621680915897"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915897"><span class="hs-identifier hs-var">dfun</span></a></span></span><span>
</span><span id="line-493"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(ClsInstEnv -&gt; ClsInstEnv) -&gt; InstEnv -&gt; Class -&gt; InstEnv
forall key elt.
Uniquable key =&gt;
(elt -&gt; elt) -&gt; UniqDFM key elt -&gt; key -&gt; UniqDFM key elt
</span><a href="GHC.Types.Unique.DFM.html#adjustUDFM"><span class="hs-identifier hs-var">adjustUDFM</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInstEnv -&gt; ClsInstEnv
</span><a href="#local-6989586621680915895"><span class="hs-identifier hs-var">adjust</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915898"><span class="hs-identifier hs-var">inst_env</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915894"><span class="hs-identifier hs-var">cls</span></a></span><span>
</span><span id="line-494"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-495"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[DFunId]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915894"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915894"><span class="hs-identifier hs-var">cls</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Type -&gt; ([DFunId], [Type], Class, [Type])
</span><a href="GHC.Tc.Utils.TcType.html#tcSplitDFunTy"><span class="hs-identifier hs-var">tcSplitDFunTy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">DFunId -&gt; Type
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915897"><span class="hs-identifier hs-var">dfun</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-496"></span><span>    </span><span id="local-6989586621680915895"><span class="annot"><span class="annottext">adjust :: ClsInstEnv -&gt; ClsInstEnv
</span><a href="#local-6989586621680915895"><span class="hs-identifier hs-var hs-var">adjust</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915893"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915893"><span class="hs-identifier hs-var">items</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ClsInst] -&gt; ClsInstEnv
</span><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-var">ClsIE</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ClsInst -&gt; Bool) -&gt; [ClsInst] -&gt; [ClsInst]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="GHC.Utils.Misc.html#filterOut"><span class="hs-identifier hs-var">filterOut</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="#local-6989586621680915892"><span class="hs-identifier hs-var">same_dfun</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915893"><span class="hs-identifier hs-var">items</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-497"></span><span>    </span><span id="local-6989586621680915892"><span class="annot"><span class="annottext">same_dfun :: ClsInst -&gt; Bool
</span><a href="#local-6989586621680915892"><span class="hs-identifier hs-var hs-var">same_dfun</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_dfun :: ClsInst -&gt; DFunId
</span><a href="GHC.Core.InstEnv.html#is_dfun"><span class="hs-identifier hs-var">is_dfun</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915890"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915890"><span class="hs-identifier hs-var">dfun'</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915897"><span class="hs-identifier hs-var">dfun</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; DFunId -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915890"><span class="hs-identifier hs-var">dfun'</span></a></span><span>
</span><span id="line-498"></span><span>
</span><span id="line-499"></span><span class="annot"><a href="GHC.Core.InstEnv.html#identicalClsInstHead"><span class="hs-identifier hs-type">identicalClsInstHead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-500"></span><span class="hs-comment">-- ^ True when when the instance heads are the same</span><span>
</span><span id="line-501"></span><span class="hs-comment">-- e.g.  both are   Eq [(a,b)]</span><span>
</span><span id="line-502"></span><span class="hs-comment">-- Used for overriding in GHCi</span><span>
</span><span id="line-503"></span><span class="hs-comment">-- Obviously should be insensitive to alpha-renaming</span><span>
</span><span id="line-504"></span><span id="identicalClsInstHead"><span class="annot"><span class="annottext">identicalClsInstHead :: ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#identicalClsInstHead"><span class="hs-identifier hs-var hs-var">identicalClsInstHead</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915889"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915889"><span class="hs-identifier hs-var">cls_nm1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915888"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915888"><span class="hs-identifier hs-var">rough1</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915887"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915887"><span class="hs-identifier hs-var">tys1</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-505"></span><span>                     </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_cls_nm :: ClsInst -&gt; Name
</span><a href="GHC.Core.InstEnv.html#is_cls_nm"><span class="hs-identifier hs-var">is_cls_nm</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915886"><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915886"><span class="hs-identifier hs-var">cls_nm2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915885"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915885"><span class="hs-identifier hs-var">rough2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915884"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915884"><span class="hs-identifier hs-var">tys2</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-506"></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915889"><span class="hs-identifier hs-var">cls_nm1</span></a></span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915886"><span class="hs-identifier hs-var">cls_nm2</span></a></span><span>
</span><span id="line-507"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Unify.html#instanceCantMatch"><span class="hs-identifier hs-var">instanceCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915888"><span class="hs-identifier hs-var">rough1</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915885"><span class="hs-identifier hs-var">rough2</span></a></span><span class="hs-special">)</span><span>  </span><span class="hs-comment">-- Fast check for no match, uses the &quot;rough match&quot; fields</span><span>
</span><span id="line-508"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcMatchTys"><span class="hs-identifier hs-var">tcMatchTys</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915887"><span class="hs-identifier hs-var">tys1</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915884"><span class="hs-identifier hs-var">tys2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-509"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcMatchTys"><span class="hs-identifier hs-var">tcMatchTys</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915884"><span class="hs-identifier hs-var">tys2</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915887"><span class="hs-identifier hs-var">tys1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-510"></span><span>
</span><span id="line-511"></span><span class="hs-comment">{-
************************************************************************
*                                                                      *
        Looking up an instance
*                                                                      *
************************************************************************

@lookupInstEnv@ looks up in a @InstEnv@, using a one-way match.  Since
the env is kept ordered, the first match must be the only one.  The
thing we are looking up can have an arbitrary &quot;flexi&quot; part.

Note [Instance lookup and orphan instances]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Suppose we are compiling a module M, and we have a zillion packages
loaded, and we are looking up an instance for C (T W).  If we find a
match in module 'X' from package 'p', should be &quot;in scope&quot;; that is,

  is p:X in the transitive closure of modules imported from M?

The difficulty is that the &quot;zillion packages&quot; might include ones loaded
through earlier invocations of the GHC API, or earlier module loads in GHCi.
They might not be in the dependencies of M itself; and if not, the instances
in them should not be visible.  #2182, #8427.

There are two cases:
  * If the instance is *not an orphan*, then module X defines C, T, or W.
    And in order for those types to be involved in typechecking M, it
    must be that X is in the transitive closure of M's imports.  So we
    can use the instance.

  * If the instance *is an orphan*, the above reasoning does not apply.
    So we keep track of the set of orphan modules transitively below M;
    this is the ie_visible field of InstEnvs, of type VisibleOrphanModules.

    If module p:X is in this set, then we can use the instance, otherwise
    we can't.

Note [Rules for instance lookup]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These functions implement the carefully-written rules in the user
manual section on &quot;overlapping instances&quot;. At risk of duplication,
here are the rules.  If the rules change, change this text and the
user manual simultaneously.  The link may be this:
http://www.haskell.org/ghc/docs/latest/html/users_guide/glasgow_exts.html#instance-overlap

The willingness to be overlapped or incoherent is a property of the
instance declaration itself, controlled as follows:

 * An instance is &quot;incoherent&quot;
   if it has an INCOHERENT pragma, or
   if it appears in a module compiled with -XIncoherentInstances.

 * An instance is &quot;overlappable&quot;
   if it has an OVERLAPPABLE or OVERLAPS pragma, or
   if it appears in a module compiled with -XOverlappingInstances, or
   if the instance is incoherent.

 * An instance is &quot;overlapping&quot;
   if it has an OVERLAPPING or OVERLAPS pragma, or
   if it appears in a module compiled with -XOverlappingInstances, or
   if the instance is incoherent.
     compiled with -XOverlappingInstances.

Now suppose that, in some client module, we are searching for an instance
of the target constraint (C ty1 .. tyn). The search works like this.

*  Find all instances `I` that *match* the target constraint; that is, the
   target constraint is a substitution instance of `I`. These instance
   declarations are the *candidates*.

*  Eliminate any candidate `IX` for which both of the following hold:

   -  There is another candidate `IY` that is strictly more specific; that
      is, `IY` is a substitution instance of `IX` but not vice versa.

   -  Either `IX` is *overlappable*, or `IY` is *overlapping*. (This
      &quot;either/or&quot; design, rather than a &quot;both/and&quot; design, allow a
      client to deliberately override an instance from a library,
      without requiring a change to the library.)

-  If exactly one non-incoherent candidate remains, select it. If all
   remaining candidates are incoherent, select an arbitrary one.
   Otherwise the search fails (i.e. when more than one surviving
   candidate is not incoherent).

-  If the selected candidate (from the previous step) is incoherent, the
   search succeeds, returning that candidate.

-  If not, find all instances that *unify* with the target constraint,
   but do not *match* it. Such non-candidate instances might match when
   the target constraint is further instantiated. If all of them are
   incoherent, the search succeeds, returning the selected candidate; if
   not, the search fails.

Notice that these rules are not influenced by flag settings in the
client module, where the instances are *used*. These rules make it
possible for a library author to design a library that relies on
overlapping instances without the client having to know.

Note [Overlapping instances]   (NB: these notes are quite old)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Overlap is permitted, but only in such a way that one can make
a unique choice when looking up.  That is, overlap is only permitted if
one template matches the other, or vice versa.  So this is ok:

  [a]  [Int]

but this is not

  (Int,a)  (b,Int)

If overlap is permitted, the list is kept most specific first, so that
the first lookup is the right choice.


For now we just use association lists.

\subsection{Avoiding a problem with overlapping}

Consider this little program:

\begin{pseudocode}
     class C a        where c :: a
     class C a =&gt; D a where d :: a

     instance C Int where c = 17
     instance D Int where d = 13

     instance C a =&gt; C [a] where c = [c]
     instance ({- C [a], -} D a) =&gt; D [a] where d = c

     instance C [Int] where c = [37]

     main = print (d :: [Int])
\end{pseudocode}

What do you think `main' prints  (assuming we have overlapping instances, and
all that turned on)?  Well, the instance for `D' at type `[a]' is defined to
be `c' at the same type, and we've got an instance of `C' at `[Int]', so the
answer is `[37]', right? (the generic `C [a]' instance shouldn't apply because
the `C [Int]' instance is more specific).

Ghc-4.04 gives `[37]', while ghc-4.06 gives `[17]', so 4.06 is wrong.  That
was easy ;-)  Let's just consult hugs for good measure.  Wait - if I use old
hugs (pre-September99), I get `[17]', and stranger yet, if I use hugs98, it
doesn't even compile!  What's going on!?

What hugs complains about is the `D [a]' instance decl.

\begin{pseudocode}
     ERROR &quot;mj.hs&quot; (line 10): Cannot build superclass instance
     *** Instance            : D [a]
     *** Context supplied    : D a
     *** Required superclass : C [a]
\end{pseudocode}

You might wonder what hugs is complaining about.  It's saying that you
need to add `C [a]' to the context of the `D [a]' instance (as appears
in comments).  But there's that `C [a]' instance decl one line above
that says that I can reduce the need for a `C [a]' instance to the
need for a `C a' instance, and in this case, I already have the
necessary `C a' instance (since we have `D a' explicitly in the
context, and `C' is a superclass of `D').

Unfortunately, the above reasoning indicates a premature commitment to the
generic `C [a]' instance.  I.e., it prematurely rules out the more specific
instance `C [Int]'.  This is the mistake that ghc-4.06 makes.  The fix is to
add the context that hugs suggests (uncomment the `C [a]'), effectively
deferring the decision about which instance to use.

Now, interestingly enough, 4.04 has this same bug, but it's covered up
in this case by a little known `optimization' that was disabled in
4.06.  Ghc-4.04 silently inserts any missing superclass context into
an instance declaration.  In this case, it silently inserts the `C
[a]', and everything happens to work out.

(See `GHC.Types.Id.Make.mkDictFunId' for the code in question.  Search for
`Mark Jones', although Mark claims no credit for the `optimization' in
question, and would rather it stopped being called the `Mark Jones
optimization' ;-)

So, what's the fix?  I think hugs has it right.  Here's why.  Let's try
something else out with ghc-4.04.  Let's add the following line:

    d' :: D a =&gt; [a]
    d' = c

Everyone raise their hand who thinks that `d :: [Int]' should give a
different answer from `d' :: [Int]'.  Well, in ghc-4.04, it does.  The
`optimization' only applies to instance decls, not to regular
bindings, giving inconsistent behavior.

Old hugs had this same bug.  Here's how we fixed it: like GHC, the
list of instances for a given class is ordered, so that more specific
instances come before more generic ones.  For example, the instance
list for C might contain:
    ..., C Int, ..., C a, ...
When we go to look for a `C Int' instance we'll get that one first.
But what if we go looking for a `C b' (`b' is unconstrained)?  We'll
pass the `C Int' instance, and keep going.  But if `b' is
unconstrained, then we don't know yet if the more specific instance
will eventually apply.  GHC keeps going, and matches on the generic `C
a'.  The fix is to, at each step, check to see if there's a reverse
match, and if so, abort the search.  This prevents hugs from
prematurely choosing a generic instance when a more specific one
exists.

--Jeff

BUT NOTE [Nov 2001]: we must actually *unify* not reverse-match in
this test.  Suppose the instance envt had
    ..., forall a b. C a a b, ..., forall a b c. C a b c, ...
(still most specific first)
Now suppose we are looking for (C x y Int), where x and y are unconstrained.
        C x y Int  doesn't match the template {a,b} C a a b
but neither does
        C a a b  match the template {x,y} C x y Int
But still x and y might subsequently be unified so they *do* match.

Simple story: unify, don't match.
-}</span><span>
</span><span id="line-732"></span><span>
</span><span id="line-733"></span><span class="hs-keyword">type</span><span> </span><span id="DFunInstType"><span class="annot"><a href="GHC.Core.InstEnv.html#DFunInstType"><span class="hs-identifier hs-var">DFunInstType</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span>
</span><span id="line-734"></span><span>        </span><span class="hs-comment">-- Just ty   =&gt; Instantiate with this type</span><span>
</span><span id="line-735"></span><span>        </span><span class="hs-comment">-- Nothing   =&gt; Instantiate with any type of this tyvar's kind</span><span>
</span><span id="line-736"></span><span>        </span><span class="hs-comment">-- See Note [DFunInstType: instantiating types]</span><span>
</span><span id="line-737"></span><span>
</span><span id="line-738"></span><span class="hs-keyword">type</span><span> </span><span id="InstMatch"><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-var">InstMatch</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#DFunInstType"><span class="hs-identifier hs-type">DFunInstType</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-739"></span><span>
</span><span id="line-740"></span><span class="hs-keyword">type</span><span> </span><span id="ClsInstLookupResult"><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInstLookupResult"><span class="hs-identifier hs-var">ClsInstLookupResult</span></a></span></span><span>
</span><span id="line-741"></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-type">InstMatch</span></a></span><span class="hs-special">]</span><span>     </span><span class="hs-comment">-- Successful matches</span><span>
</span><span id="line-742"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span>       </span><span class="hs-comment">-- These don't match but do unify</span><span>
</span><span id="line-743"></span><span>       </span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-type">InstMatch</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-special">)</span><span>   </span><span class="hs-comment">-- Unsafe overlapped instances under Safe Haskell</span><span>
</span><span id="line-744"></span><span>                         </span><span class="hs-comment">-- (see Note [Safe Haskell Overlapping Instances] in</span><span>
</span><span id="line-745"></span><span>                         </span><span class="hs-comment">-- GHC.Tc.Solver).</span><span>
</span><span id="line-746"></span><span>
</span><span id="line-747"></span><span class="hs-comment">{-
Note [DFunInstType: instantiating types]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A successful match is a ClsInst, together with the types at which
        the dfun_id in the ClsInst should be instantiated
The instantiating types are (Either TyVar Type)s because the dfun
might have some tyvars that *only* appear in arguments
        dfun :: forall a b. C a b, Ord b =&gt; D [a]
When we match this against D [ty], we return the instantiating types
        [Just ty, Nothing]
where the 'Nothing' indicates that 'b' can be freely instantiated.
(The caller instantiates it to a flexi type variable, which will
 presumably later become fixed via functional dependencies.)
-}</span><span>
</span><span id="line-761"></span><span>
</span><span id="line-762"></span><span class="hs-comment">-- |Look up an instance in the given instance environment. The given class application must match exactly</span><span>
</span><span id="line-763"></span><span class="hs-comment">-- one instance and the match may not contain any flexi type variables.  If the lookup is unsuccessful,</span><span>
</span><span id="line-764"></span><span class="hs-comment">-- yield 'Left errorMessage'.</span><span>
</span><span id="line-765"></span><span class="annot"><a href="GHC.Core.InstEnv.html#lookupUniqueInstEnv"><span class="hs-identifier hs-type">lookupUniqueInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span>
</span><span id="line-766"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-767"></span><span>                    </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="GHC.Utils.Error.html#MsgDoc"><span class="hs-identifier hs-type">MsgDoc</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-768"></span><span id="lookupUniqueInstEnv"><span class="annot"><span class="annottext">lookupUniqueInstEnv :: InstEnvs -&gt; Class -&gt; [Type] -&gt; Either SDoc (ClsInst, [Type])
</span><a href="GHC.Core.InstEnv.html#lookupUniqueInstEnv"><span class="hs-identifier hs-var hs-var">lookupUniqueInstEnv</span></a></span></span><span> </span><span id="local-6989586621680915881"><span class="annot"><span class="annottext">InstEnvs
</span><a href="#local-6989586621680915881"><span class="hs-identifier hs-var">instEnv</span></a></span></span><span> </span><span id="local-6989586621680915880"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915880"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621680915879"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915879"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-769"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; InstEnvs -&gt; Class -&gt; [Type] -&gt; ClsInstLookupResult
</span><a href="GHC.Core.InstEnv.html#lookupInstEnv"><span class="hs-identifier hs-var">lookupInstEnv</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="annot"><span class="annottext">InstEnvs
</span><a href="#local-6989586621680915881"><span class="hs-identifier hs-var">instEnv</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915880"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915879"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-770"></span><span>      </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">(</span><span id="local-6989586621680915878"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915878"><span class="hs-identifier hs-var">inst</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915877"><span class="annot"><span class="annottext">[DFunInstType]
</span><a href="#local-6989586621680915877"><span class="hs-identifier hs-var">inst_tys</span></a></span></span><span class="hs-special">)</span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>
</span><span id="line-771"></span><span>             </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915876"><span class="hs-identifier hs-var">noFlexiVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(ClsInst, [Type]) -&gt; Either SDoc (ClsInst, [Type])
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915878"><span class="hs-identifier hs-var">inst</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915875"><span class="hs-identifier hs-var">inst_tys'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-772"></span><span>             </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Either SDoc (ClsInst, [Type])
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; Either SDoc (ClsInst, [Type]))
-&gt; SDoc -&gt; Either SDoc (ClsInst, [Type])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flexible type variable:&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-773"></span><span>                                    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Type -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">(Type -&gt; SDoc) -&gt; Type -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [Type] -&gt; Type
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; TyCon
</span><a href="GHC.Core.Class.html#classTyCon"><span class="hs-identifier hs-var hs-var">classTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915880"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915879"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-774"></span><span>             </span><span class="hs-keyword">where</span><span>
</span><span id="line-775"></span><span>               </span><span id="local-6989586621680915875"><span class="annot"><span class="annottext">inst_tys' :: [Type]
</span><a href="#local-6989586621680915875"><span class="hs-identifier hs-var hs-var">inst_tys'</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680915872"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680915872"><span class="annot"><span class="annottext">Type
</span><a href="#local-6989586621680915872"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[DFunInstType]
</span><a href="#local-6989586621680915877"><span class="hs-identifier hs-var">inst_tys</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-776"></span><span>               </span><span id="local-6989586621680915876"><span class="annot"><span class="annottext">noFlexiVar :: Bool
</span><a href="#local-6989586621680915876"><span class="hs-identifier hs-var hs-var">noFlexiVar</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(DFunInstType -&gt; Bool) -&gt; [DFunInstType] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#all"><span class="hs-identifier hs-var">all</span></a></span><span> </span><span class="annot"><span class="annottext">DFunInstType -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">[DFunInstType]
</span><a href="#local-6989586621680915877"><span class="hs-identifier hs-var">inst_tys</span></a></span><span>
</span><span id="line-777"></span><span>      </span><span id="local-6989586621680915870"><span class="annot"><span class="annottext">ClsInstLookupResult
</span><a href="#local-6989586621680915870"><span class="hs-identifier hs-var">_other</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; Either SDoc (ClsInst, [Type])
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">(SDoc -&gt; Either SDoc (ClsInst, [Type]))
-&gt; SDoc -&gt; Either SDoc (ClsInst, [Type])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;instance not found&quot;</span></span><span> </span><span class="annot"><span class="annottext">SDoc -&gt; SDoc -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-778"></span><span>                       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Type -&gt; SDoc
forall a. Outputable a =&gt; a -&gt; SDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">(Type -&gt; SDoc) -&gt; Type -&gt; SDoc
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; [Type] -&gt; Type
</span><a href="GHC.Core.TyCo.Rep.html#mkTyConApp"><span class="hs-identifier hs-var">mkTyConApp</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Class -&gt; TyCon
</span><a href="GHC.Core.Class.html#classTyCon"><span class="hs-identifier hs-var hs-var">classTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915880"><span class="hs-identifier hs-var">cls</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915879"><span class="hs-identifier hs-var">tys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-779"></span><span>
</span><span id="line-780"></span><span class="annot"><a href="GHC.Core.InstEnv.html#lookupInstEnv%27"><span class="hs-identifier hs-type">lookupInstEnv'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnv"><span class="hs-identifier hs-type">InstEnv</span></a></span><span>          </span><span class="hs-comment">-- InstEnv to look in</span><span>
</span><span id="line-781"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#VisibleOrphanModules"><span class="hs-identifier hs-type">VisibleOrphanModules</span></a></span><span>   </span><span class="hs-comment">-- But filter against this</span><span>
</span><span id="line-782"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>  </span><span class="hs-comment">-- What we are looking for</span><span>
</span><span id="line-783"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-type">InstMatch</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span>    </span><span class="hs-comment">-- Successful matches</span><span>
</span><span id="line-784"></span><span>                   </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>      </span><span class="hs-comment">-- These don't match but do unify</span><span>
</span><span id="line-785"></span><span>                                   </span><span class="hs-comment">-- (no incoherent ones in here)</span><span>
</span><span id="line-786"></span><span class="hs-comment">-- The second component of the result pair happens when we look up</span><span>
</span><span id="line-787"></span><span class="hs-comment">--      Foo [a]</span><span>
</span><span id="line-788"></span><span class="hs-comment">-- in an InstEnv that has entries for</span><span>
</span><span id="line-789"></span><span class="hs-comment">--      Foo [Int]</span><span>
</span><span id="line-790"></span><span class="hs-comment">--      Foo [b]</span><span>
</span><span id="line-791"></span><span class="hs-comment">-- Then which we choose would depend on the way in which 'a'</span><span>
</span><span id="line-792"></span><span class="hs-comment">-- is instantiated.  So we report that Foo [b] is a match (mapping b-&gt;a)</span><span>
</span><span id="line-793"></span><span class="hs-comment">-- but Foo [Int] is a unifier.  This gives the caller a better chance of</span><span>
</span><span id="line-794"></span><span class="hs-comment">-- giving a suitable error message</span><span>
</span><span id="line-795"></span><span>
</span><span id="line-796"></span><span id="lookupInstEnv%27"><span class="annot"><span class="annottext">lookupInstEnv' :: InstEnv
-&gt; VisibleOrphanModules
-&gt; Class
-&gt; [Type]
-&gt; ([InstMatch], [ClsInst])
</span><a href="GHC.Core.InstEnv.html#lookupInstEnv%27"><span class="hs-identifier hs-var hs-var">lookupInstEnv'</span></a></span></span><span> </span><span id="local-6989586621680915868"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915868"><span class="hs-identifier hs-var">ie</span></a></span></span><span> </span><span id="local-6989586621680915867"><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915867"><span class="hs-identifier hs-var">vis_mods</span></a></span></span><span> </span><span id="local-6989586621680915866"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915866"><span class="hs-identifier hs-var">cls</span></a></span></span><span> </span><span id="local-6989586621680915865"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915865"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-797"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915864"><span class="hs-identifier hs-var">lookup</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915868"><span class="hs-identifier hs-var">ie</span></a></span><span>
</span><span id="line-798"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-799"></span><span>    </span><span id="local-6989586621680915863"><span class="annot"><span class="annottext">rough_tcs :: [Maybe Name]
</span><a href="#local-6989586621680915863"><span class="hs-identifier hs-var hs-var">rough_tcs</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Maybe Name]
</span><a href="GHC.Core.Unify.html#roughMatchTcs"><span class="hs-identifier hs-var">roughMatchTcs</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915865"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-800"></span><span>    </span><span id="local-6989586621680915861"><span class="annot"><span class="annottext">all_tvs :: Bool
</span><a href="#local-6989586621680915861"><span class="hs-identifier hs-var hs-var">all_tvs</span></a></span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Maybe Name -&gt; Bool) -&gt; [Maybe Name] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; (a -&gt; Bool) -&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#all"><span class="hs-identifier hs-var">all</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Name -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915863"><span class="hs-identifier hs-var">rough_tcs</span></a></span><span>
</span><span id="line-801"></span><span>
</span><span id="line-802"></span><span>    </span><span class="hs-comment">--------------</span><span>
</span><span id="line-803"></span><span>    </span><span id="local-6989586621680915864"><span class="annot"><span class="annottext">lookup :: InstEnv -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915864"><span class="hs-identifier hs-var hs-var">lookup</span></a></span></span><span> </span><span id="local-6989586621680915859"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915859"><span class="hs-identifier hs-var">env</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">InstEnv -&gt; Class -&gt; Maybe ClsInstEnv
forall key elt.
Uniquable key =&gt;
UniqDFM key elt -&gt; key -&gt; Maybe elt
</span><a href="GHC.Types.Unique.DFM.html#lookupUDFM"><span class="hs-identifier hs-var">lookupUDFM</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915859"><span class="hs-identifier hs-var">env</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915866"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-804"></span><span>                   </span><span class="annot"><span class="annottext">Maybe ClsInstEnv
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>   </span><span class="hs-comment">-- No instances for this class</span><span>
</span><span id="line-805"></span><span>                   </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsIE"><span class="hs-identifier hs-type">ClsIE</span></a></span><span> </span><span id="local-6989586621680915858"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915858"><span class="hs-identifier hs-var">insts</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915858"><span class="hs-identifier hs-var">insts</span></a></span><span>
</span><span id="line-806"></span><span>
</span><span id="line-807"></span><span>    </span><span class="hs-comment">--------------</span><span>
</span><span id="line-808"></span><span>    </span><span id="local-6989586621680915857"><span class="annot"><span class="annottext">find :: [InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var hs-var">find</span></a></span></span><span> </span><span id="local-6989586621680915844"><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915844"><span class="hs-identifier hs-var">ms</span></a></span></span><span> </span><span id="local-6989586621680915843"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915843"><span class="hs-identifier hs-var">us</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915844"><span class="hs-identifier hs-var">ms</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915843"><span class="hs-identifier hs-var">us</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-809"></span><span>    </span><span class="annot"><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span id="local-6989586621680915842"><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span></span><span> </span><span id="local-6989586621680915841"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915840"><span class="annot"><span class="annottext">item :: ClsInst
</span><a href="#local-6989586621680915840"><span class="hs-identifier hs-var">item</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInst"><span class="hs-identifier hs-type">ClsInst</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">is_tcs :: ClsInst -&gt; [Maybe Name]
</span><a href="GHC.Core.InstEnv.html#is_tcs"><span class="hs-identifier hs-var">is_tcs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915839"><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915839"><span class="hs-identifier hs-var">mb_tcs</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tvs :: ClsInst -&gt; [DFunId]
</span><a href="GHC.Core.InstEnv.html#is_tvs"><span class="hs-identifier hs-var">is_tvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915838"><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915838"><span class="hs-identifier hs-var">tpl_tvs</span></a></span></span><span>
</span><span id="line-810"></span><span>                              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">is_tys :: ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var">is_tys</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915837"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915837"><span class="hs-identifier hs-var">tpl_tys</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680915836"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-811"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">VisibleOrphanModules -&gt; ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#instIsVisible"><span class="hs-identifier hs-var">instIsVisible</span></a></span><span> </span><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915867"><span class="hs-identifier hs-var">vis_mods</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915840"><span class="hs-identifier hs-var">item</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-812"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span><span>  </span><span class="hs-comment">-- See Note [Instance lookup and orphan instances]</span><span>
</span><span id="line-813"></span><span>
</span><span id="line-814"></span><span>        </span><span class="hs-comment">-- Fast check for no match, uses the &quot;rough match&quot; fields</span><span>
</span><span id="line-815"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">[Maybe Name] -&gt; [Maybe Name] -&gt; Bool
</span><a href="GHC.Core.Unify.html#instanceCantMatch"><span class="hs-identifier hs-var">instanceCantMatch</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915863"><span class="hs-identifier hs-var">rough_tcs</span></a></span><span> </span><span class="annot"><span class="annottext">[Maybe Name]
</span><a href="#local-6989586621680915839"><span class="hs-identifier hs-var">mb_tcs</span></a></span><span>
</span><span id="line-816"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-817"></span><span>
</span><span id="line-818"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621680915835"><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680915835"><span class="hs-identifier hs-var">subst</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcMatchTys"><span class="hs-identifier hs-var">tcMatchTys</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915837"><span class="hs-identifier hs-var">tpl_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915865"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-819"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915840"><span class="hs-identifier hs-var">item</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(DFunId -&gt; DFunInstType) -&gt; [DFunId] -&gt; [DFunInstType]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TCvSubst -&gt; DFunId -&gt; DFunInstType
</span><a href="GHC.Core.TyCo.Subst.html#lookupTyVar"><span class="hs-identifier hs-var">lookupTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><a href="#local-6989586621680915835"><span class="hs-identifier hs-var">subst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915838"><span class="hs-identifier hs-var">tpl_tvs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-820"></span><span>
</span><span id="line-821"></span><span>        </span><span class="hs-comment">-- Does not match, so next check whether the things unify</span><span>
</span><span id="line-822"></span><span>        </span><span class="hs-comment">-- See Note [Overlapping instances]</span><span>
</span><span id="line-823"></span><span>        </span><span class="hs-comment">-- Ignore ones that are incoherent: Note [Incoherent instances]</span><span>
</span><span id="line-824"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier hs-var">isIncoherent</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915840"><span class="hs-identifier hs-var">item</span></a></span><span>
</span><span id="line-825"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-826"></span><span>
</span><span id="line-827"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-828"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">ASSERT2</span><span class="hs-special">(</span><span> </span><span class="hs-identifier">tyCoVarsOfTypes</span><span> </span><span class="hs-identifier">tys</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">disjointVarSet</span><span class="hs-special">`</span><span> </span><span class="hs-identifier">tpl_tv_set</span><span class="hs-special">,</span><span>
</span><span id="line-829"></span><span>                 </span><span class="hs-special">(</span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">cls</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tys</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">all_tvs</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$$</span><span>
</span><span id="line-830"></span><span>                 </span><span class="hs-special">(</span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tpl_tvs</span><span> </span><span class="hs-operator">&lt;+&gt;</span><span> </span><span class="hs-identifier">ppr</span><span> </span><span class="hs-identifier">tpl_tys</span><span class="hs-special">)</span><span>
</span><span id="line-831"></span><span>                </span><span class="hs-special">)</span><span>
</span><span id="line-832"></span><span>                </span><span class="hs-comment">-- Unification will break badly if the variables overlap</span><span>
</span><span id="line-833"></span><span>                </span><span class="hs-comment">-- They shouldn't because we allocate separate uniques for them</span><span>
</span><span id="line-834"></span><span>                </span><span class="hs-comment">-- See Note [Template tyvars are fresh]</span><span>
</span><span id="line-835"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">(DFunId -&gt; BindFlag) -&gt; [Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcUnifyTys"><span class="hs-identifier hs-var">tcUnifyTys</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; BindFlag
</span><a href="GHC.Core.InstEnv.html#instanceBindFun"><span class="hs-identifier hs-var">instanceBindFun</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915837"><span class="hs-identifier hs-var">tpl_tys</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915865"><span class="hs-identifier hs-var">tys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-836"></span><span>            </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TCvSubst
</span><span class="hs-identifier">_</span></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915840"><span class="hs-identifier hs-var">item</span></a></span><span class="annot"><span class="annottext">ClsInst -&gt; [ClsInst] -&gt; [ClsInst]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-837"></span><span>            </span><span class="annot"><span class="annottext">Maybe TCvSubst
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [ClsInst] -&gt; [ClsInst] -&gt; ([InstMatch], [ClsInst])
</span><a href="#local-6989586621680915857"><span class="hs-identifier hs-var">find</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915842"><span class="hs-identifier hs-var">ms</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915841"><span class="hs-identifier hs-var">us</span></a></span><span>        </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915836"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-838"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-839"></span><span>        </span><span id="local-6989586621680915831"><span class="annot"><span class="annottext">tpl_tv_set :: TyCoVarSet
</span><a href="#local-6989586621680915831"><span class="hs-identifier hs-var hs-var">tpl_tv_set</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[DFunId] -&gt; TyCoVarSet
</span><a href="GHC.Types.Var.Set.html#mkVarSet"><span class="hs-identifier hs-var">mkVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">[DFunId]
</span><a href="#local-6989586621680915838"><span class="hs-identifier hs-var">tpl_tvs</span></a></span><span>
</span><span id="line-840"></span><span>
</span><span id="line-841"></span><span class="hs-comment">---------------</span><span>
</span><span id="line-842"></span><span class="hs-comment">-- This is the common way to call this function.</span><span>
</span><span id="line-843"></span><span class="annot"><a href="GHC.Core.InstEnv.html#lookupInstEnv"><span class="hs-identifier hs-type">lookupInstEnv</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>              </span><span class="hs-comment">-- Check Safe Haskell overlap restrictions</span><span>
</span><span id="line-844"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span>          </span><span class="hs-comment">-- External and home package inst-env</span><span>
</span><span id="line-845"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Class.html#Class"><span class="hs-identifier hs-type">Class</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.TyCo.Rep.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">]</span><span>   </span><span class="hs-comment">-- What we are looking for</span><span>
</span><span id="line-846"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#ClsInstLookupResult"><span class="hs-identifier hs-type">ClsInstLookupResult</span></a></span><span>
</span><span id="line-847"></span><span class="hs-comment">-- ^ See Note [Rules for instance lookup]</span><span>
</span><span id="line-848"></span><span class="hs-comment">-- ^ See Note [Safe Haskell Overlapping Instances] in &quot;GHC.Tc.Solver&quot;</span><span>
</span><span id="line-849"></span><span class="hs-comment">-- ^ See Note [Safe Haskell Overlapping Instances Implementation] in &quot;GHC.Tc.Solver&quot;</span><span>
</span><span id="line-850"></span><span id="lookupInstEnv"><span class="annot"><span class="annottext">lookupInstEnv :: Bool -&gt; InstEnvs -&gt; Class -&gt; [Type] -&gt; ClsInstLookupResult
</span><a href="GHC.Core.InstEnv.html#lookupInstEnv"><span class="hs-identifier hs-var hs-var">lookupInstEnv</span></a></span></span><span> </span><span id="local-6989586621680915826"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915826"><span class="hs-identifier hs-var">check_overlap_safe</span></a></span></span><span>
</span><span id="line-851"></span><span>              </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstEnvs"><span class="hs-identifier hs-type">InstEnvs</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ie_global :: InstEnvs -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#ie_global"><span class="hs-identifier hs-var">ie_global</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915825"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915825"><span class="hs-identifier hs-var">pkg_ie</span></a></span></span><span>
</span><span id="line-852"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ie_local :: InstEnvs -&gt; InstEnv
</span><a href="GHC.Core.InstEnv.html#ie_local"><span class="hs-identifier hs-var">ie_local</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915824"><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915824"><span class="hs-identifier hs-var">home_ie</span></a></span></span><span>
</span><span id="line-853"></span><span>                        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ie_visible :: InstEnvs -&gt; VisibleOrphanModules
</span><a href="GHC.Core.InstEnv.html#ie_visible"><span class="hs-identifier hs-var">ie_visible</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621680915823"><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915823"><span class="hs-identifier hs-var">vis_mods</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-854"></span><span>              </span><span id="local-6989586621680915822"><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915822"><span class="hs-identifier hs-var">cls</span></a></span></span><span>
</span><span id="line-855"></span><span>              </span><span id="local-6989586621680915821"><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915821"><span class="hs-identifier hs-var">tys</span></a></span></span><span>
</span><span id="line-856"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-comment">-- pprTrace &quot;lookupInstEnv&quot; (ppr cls &lt;+&gt; ppr tys $$ ppr home_ie) $</span><span>
</span><span id="line-857"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915820"><span class="hs-identifier hs-var">final_matches</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915819"><span class="hs-identifier hs-var">final_unifs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915818"><span class="hs-identifier hs-var">unsafe_overlapped</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-858"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-859"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680915817"><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915817"><span class="hs-identifier hs-var">home_matches</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680915816"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915816"><span class="hs-identifier hs-var">home_unifs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnv
-&gt; VisibleOrphanModules
-&gt; Class
-&gt; [Type]
-&gt; ([InstMatch], [ClsInst])
</span><a href="GHC.Core.InstEnv.html#lookupInstEnv%27"><span class="hs-identifier hs-var">lookupInstEnv'</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915824"><span class="hs-identifier hs-var">home_ie</span></a></span><span> </span><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915823"><span class="hs-identifier hs-var">vis_mods</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915822"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915821"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-860"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621680915815"><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915815"><span class="hs-identifier hs-var">pkg_matches</span></a></span></span><span class="hs-special">,</span><span>  </span><span id="local-6989586621680915814"><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915814"><span class="hs-identifier hs-var">pkg_unifs</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstEnv
-&gt; VisibleOrphanModules
-&gt; Class
-&gt; [Type]
-&gt; ([InstMatch], [ClsInst])
</span><a href="GHC.Core.InstEnv.html#lookupInstEnv%27"><span class="hs-identifier hs-var">lookupInstEnv'</span></a></span><span> </span><span class="annot"><span class="annottext">InstEnv
</span><a href="#local-6989586621680915825"><span class="hs-identifier hs-var">pkg_ie</span></a></span><span>  </span><span class="annot"><span class="annottext">VisibleOrphanModules
</span><a href="#local-6989586621680915823"><span class="hs-identifier hs-var">vis_mods</span></a></span><span> </span><span class="annot"><span class="annottext">Class
</span><a href="#local-6989586621680915822"><span class="hs-identifier hs-var">cls</span></a></span><span> </span><span class="annot"><span class="annottext">[Type]
</span><a href="#local-6989586621680915821"><span class="hs-identifier hs-var">tys</span></a></span><span>
</span><span id="line-861"></span><span>    </span><span id="local-6989586621680915813"><span class="annot"><span class="annottext">all_matches :: [InstMatch]
</span><a href="#local-6989586621680915813"><span class="hs-identifier hs-var hs-var">all_matches</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915817"><span class="hs-identifier hs-var">home_matches</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [InstMatch] -&gt; [InstMatch]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915815"><span class="hs-identifier hs-var">pkg_matches</span></a></span><span>
</span><span id="line-862"></span><span>    </span><span id="local-6989586621680915812"><span class="annot"><span class="annottext">all_unifs :: [ClsInst]
</span><a href="#local-6989586621680915812"><span class="hs-identifier hs-var hs-var">all_unifs</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915816"><span class="hs-identifier hs-var">home_unifs</span></a></span><span>   </span><span class="annot"><span class="annottext">[ClsInst] -&gt; [ClsInst] -&gt; [ClsInst]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915814"><span class="hs-identifier hs-var">pkg_unifs</span></a></span><span>
</span><span id="line-863"></span><span>    </span><span id="local-6989586621680915820"><span class="annot"><span class="annottext">final_matches :: [InstMatch]
</span><a href="#local-6989586621680915820"><span class="hs-identifier hs-var hs-var">final_matches</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(InstMatch -&gt; [InstMatch] -&gt; [InstMatch])
-&gt; [InstMatch] -&gt; [InstMatch] -&gt; [InstMatch]
forall (t :: * -&gt; *) a b.
Foldable t =&gt;
(a -&gt; b -&gt; b) -&gt; b -&gt; t a -&gt; b
</span><a href="../../base/src/Data.Foldable.html#foldr"><span class="hs-identifier hs-var">foldr</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
</span><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-var">insert_overlapping</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915813"><span class="hs-identifier hs-var">all_matches</span></a></span><span>
</span><span id="line-864"></span><span>        </span><span class="hs-comment">-- Even if the unifs is non-empty (an error situation)</span><span>
</span><span id="line-865"></span><span>        </span><span class="hs-comment">-- we still prune the matches, so that the error message isn't</span><span>
</span><span id="line-866"></span><span>        </span><span class="hs-comment">-- misleading (complaining of multiple matches when some should be</span><span>
</span><span id="line-867"></span><span>        </span><span class="hs-comment">-- overlapped away)</span><span>
</span><span id="line-868"></span><span>
</span><span id="line-869"></span><span>    </span><span id="local-6989586621680915818"><span class="annot"><span class="annottext">unsafe_overlapped :: [InstMatch]
</span><a href="#local-6989586621680915818"><span class="hs-identifier hs-var hs-var">unsafe_overlapped</span></a></span></span><span>
</span><span id="line-870"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915820"><span class="hs-identifier hs-var">final_matches</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-871"></span><span>           </span><span class="hs-special">[</span><span id="local-6989586621680915808"><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915808"><span class="hs-identifier hs-var">match</span></a></span></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch]
forall {b}. (ClsInst, b) -&gt; [InstMatch]
</span><a href="#local-6989586621680915807"><span class="hs-identifier hs-var">check_safe</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915808"><span class="hs-identifier hs-var">match</span></a></span><span>
</span><span id="line-872"></span><span>           </span><span class="annot"><span class="annottext">[InstMatch]
</span><span class="hs-identifier">_</span></span><span>       </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-873"></span><span>
</span><span id="line-874"></span><span>    </span><span class="hs-comment">-- If the selected match is incoherent, discard all unifiers</span><span>
</span><span id="line-875"></span><span>    </span><span id="local-6989586621680915819"><span class="annot"><span class="annottext">final_unifs :: [ClsInst]
</span><a href="#local-6989586621680915819"><span class="hs-identifier hs-var hs-var">final_unifs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915820"><span class="hs-identifier hs-var">final_matches</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-876"></span><span>                    </span><span class="hs-special">(</span><span id="local-6989586621680915806"><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915806"><span class="hs-identifier hs-var">m</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[InstMatch]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier hs-var">isIncoherent</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">InstMatch -&gt; ClsInst
forall a b. (a, b) -&gt; a
</span><a href="../../base/src/Data.Tuple.html#fst"><span class="hs-identifier hs-var">fst</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915806"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-877"></span><span>                    </span><span class="annot"><span class="annottext">[InstMatch]
</span><span class="hs-identifier">_</span></span><span>                            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[ClsInst]
</span><a href="#local-6989586621680915812"><span class="hs-identifier hs-var">all_unifs</span></a></span><span>
</span><span id="line-878"></span><span>
</span><span id="line-879"></span><span>    </span><span class="hs-comment">-- NOTE [Safe Haskell isSafeOverlap]</span><span>
</span><span id="line-880"></span><span>    </span><span class="hs-comment">-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><span>
</span><span id="line-881"></span><span>    </span><span class="hs-comment">-- We restrict code compiled in 'Safe' mode from overriding code</span><span>
</span><span id="line-882"></span><span>    </span><span class="hs-comment">-- compiled in any other mode. The rationale is that code compiled</span><span>
</span><span id="line-883"></span><span>    </span><span class="hs-comment">-- in 'Safe' mode is code that is untrusted by the ghc user. So</span><span>
</span><span id="line-884"></span><span>    </span><span class="hs-comment">-- we shouldn't let that code change the behaviour of code the</span><span>
</span><span id="line-885"></span><span>    </span><span class="hs-comment">-- user didn't compile in 'Safe' mode since that's the code they</span><span>
</span><span id="line-886"></span><span>    </span><span class="hs-comment">-- trust. So 'Safe' instances can only overlap instances from the</span><span>
</span><span id="line-887"></span><span>    </span><span class="hs-comment">-- same module. A same instance origin policy for safe compiled</span><span>
</span><span id="line-888"></span><span>    </span><span class="hs-comment">-- instances.</span><span>
</span><span id="line-889"></span><span>    </span><span id="local-6989586621680915807"><span class="annot"><span class="annottext">check_safe :: (ClsInst, b) -&gt; [InstMatch]
</span><a href="#local-6989586621680915807"><span class="hs-identifier hs-var hs-var">check_safe</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915805"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915805"><span class="hs-identifier hs-var">inst</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span>
</span><span id="line-890"></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915826"><span class="hs-identifier hs-var">check_overlap_safe</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="#local-6989586621680915804"><span class="hs-identifier hs-var">unsafeTopInstance</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915805"><span class="hs-identifier hs-var">inst</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-891"></span><span>                </span><span class="hs-comment">-- make sure it only overlaps instances from the same module</span><span>
</span><span id="line-892"></span><span>                </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[InstMatch] -&gt; [InstMatch] -&gt; [InstMatch]
forall {b}. [(ClsInst, b)] -&gt; [(ClsInst, b)] -&gt; [(ClsInst, b)]
</span><a href="#local-6989586621680915803"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915813"><span class="hs-identifier hs-var">all_matches</span></a></span><span>
</span><span id="line-893"></span><span>                </span><span class="hs-comment">-- most specific is from a trusted location.</span><span>
</span><span id="line-894"></span><span>                </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-895"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-896"></span><span>            </span><span id="local-6989586621680915803"><span class="annot"><span class="annottext">go :: [(ClsInst, b)] -&gt; [(ClsInst, b)] -&gt; [(ClsInst, b)]
</span><a href="#local-6989586621680915803"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680915801"><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915801"><span class="hs-identifier hs-var">bad</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915801"><span class="hs-identifier hs-var">bad</span></a></span><span>
</span><span id="line-897"></span><span>            </span><span class="annot"><a href="#local-6989586621680915803"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span id="local-6989586621680915800"><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915800"><span class="hs-identifier hs-var">bad</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915799"><span class="annot"><span class="annottext">i :: (ClsInst, b)
</span><a href="#local-6989586621680915799"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span id="local-6989586621680915798"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915798"><span class="hs-identifier hs-var">x</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">b
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621680915797"><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915797"><span class="hs-identifier hs-var">unchecked</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-898"></span><span>                </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
forall {p}. NamedThing p =&gt; p -&gt; Bool
</span><a href="#local-6989586621680915796"><span class="hs-identifier hs-var">inSameMod</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915798"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isOverlappable"><span class="hs-identifier hs-var">isOverlappable</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915798"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-899"></span><span>                    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">[(ClsInst, b)] -&gt; [(ClsInst, b)] -&gt; [(ClsInst, b)]
</span><a href="#local-6989586621680915803"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915800"><span class="hs-identifier hs-var">bad</span></a></span><span> </span><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915797"><span class="hs-identifier hs-var">unchecked</span></a></span><span>
</span><span id="line-900"></span><span>                    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">[(ClsInst, b)] -&gt; [(ClsInst, b)] -&gt; [(ClsInst, b)]
</span><a href="#local-6989586621680915803"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(ClsInst, b)
</span><a href="#local-6989586621680915799"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">(ClsInst, b) -&gt; [(ClsInst, b)] -&gt; [(ClsInst, b)]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915800"><span class="hs-identifier hs-var">bad</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[(ClsInst, b)]
</span><a href="#local-6989586621680915797"><span class="hs-identifier hs-var">unchecked</span></a></span><span>
</span><span id="line-901"></span><span>
</span><span id="line-902"></span><span>            </span><span id="local-6989586621680915796"><span class="annot"><span class="annottext">inSameMod :: p -&gt; Bool
</span><a href="#local-6989586621680915796"><span class="hs-identifier hs-var hs-var">inSameMod</span></a></span></span><span> </span><span id="local-6989586621680915787"><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621680915787"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-903"></span><span>                </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621680915783"><span class="annot"><span class="annottext">na :: Name
</span><a href="#local-6989586621680915783"><span class="hs-identifier hs-var hs-var">na</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="annot"><span class="annottext">(Name -&gt; Name) -&gt; Name -&gt; Name
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915805"><span class="hs-identifier hs-var">inst</span></a></span><span>
</span><span id="line-904"></span><span>                    </span><span id="local-6989586621680915782"><span class="annot"><span class="annottext">la :: Bool
</span><a href="#local-6989586621680915782"><span class="hs-identifier hs-var hs-var">la</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Bool
</span><a href="GHC.Types.Name.html#isInternalName"><span class="hs-identifier hs-var">isInternalName</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915783"><span class="hs-identifier hs-var">na</span></a></span><span>
</span><span id="line-905"></span><span>                    </span><span id="local-6989586621680915778"><span class="annot"><span class="annottext">nb :: Name
</span><a href="#local-6989586621680915778"><span class="hs-identifier hs-var hs-var">nb</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="annot"><span class="annottext">(Name -&gt; Name) -&gt; Name -&gt; Name
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">p -&gt; Name
forall a. NamedThing a =&gt; a -&gt; Name
</span><a href="GHC.Types.Name.html#getName"><span class="hs-identifier hs-var">getName</span></a></span><span> </span><span class="annot"><span class="annottext">p
</span><a href="#local-6989586621680915787"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-906"></span><span>                    </span><span id="local-6989586621680915777"><span class="annot"><span class="annottext">lb :: Bool
</span><a href="#local-6989586621680915777"><span class="hs-identifier hs-var hs-var">lb</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; Bool
</span><a href="GHC.Types.Name.html#isInternalName"><span class="hs-identifier hs-var">isInternalName</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915778"><span class="hs-identifier hs-var">nb</span></a></span><span>
</span><span id="line-907"></span><span>                </span><span class="hs-keyword">in</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915782"><span class="hs-identifier hs-var">la</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915777"><span class="hs-identifier hs-var">lb</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Name -&gt; Module
Name -&gt; Module
</span><a href="GHC.Types.Name.html#nameModule"><span class="hs-identifier hs-var">nameModule</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915783"><span class="hs-identifier hs-var">na</span></a></span><span> </span><span class="annot"><span class="annottext">Module -&gt; Module -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Name -&gt; Module
Name -&gt; Module
</span><a href="GHC.Types.Name.html#nameModule"><span class="hs-identifier hs-var">nameModule</span></a></span><span> </span><span class="annot"><span class="annottext">Name
</span><a href="#local-6989586621680915778"><span class="hs-identifier hs-var">nb</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-908"></span><span>
</span><span id="line-909"></span><span>    </span><span class="hs-comment">-- We consider the most specific instance unsafe when it both:</span><span>
</span><span id="line-910"></span><span>    </span><span class="hs-comment">--   (1) Comes from a module compiled as `Safe`</span><span>
</span><span id="line-911"></span><span>    </span><span class="hs-comment">--   (2) Is an orphan instance, OR, an instance for a MPTC</span><span>
</span><span id="line-912"></span><span>    </span><span id="local-6989586621680915804"><span class="annot"><span class="annottext">unsafeTopInstance :: ClsInst -&gt; Bool
</span><a href="#local-6989586621680915804"><span class="hs-identifier hs-var hs-var">unsafeTopInstance</span></a></span></span><span> </span><span id="local-6989586621680915772"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915772"><span class="hs-identifier hs-var">inst</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">OverlapFlag -&gt; Bool
</span><a href="GHC.Types.Basic.html#isSafeOverlap"><span class="hs-identifier hs-var hs-var">isSafeOverlap</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; OverlapFlag
</span><a href="GHC.Core.InstEnv.html#is_flag"><span class="hs-identifier hs-var hs-var">is_flag</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915772"><span class="hs-identifier hs-var">inst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span>
</span><span id="line-913"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IsOrphan -&gt; Bool
</span><a href="GHC.Core.html#isOrphan"><span class="hs-identifier hs-var">isOrphan</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; IsOrphan
</span><a href="GHC.Core.InstEnv.html#is_orphan"><span class="hs-identifier hs-var hs-var">is_orphan</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915772"><span class="hs-identifier hs-var">inst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">Class -&gt; Int
</span><a href="GHC.Core.Class.html#classArity"><span class="hs-identifier hs-var">classArity</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; Class
</span><a href="GHC.Core.InstEnv.html#is_cls"><span class="hs-identifier hs-var hs-var">is_cls</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915772"><span class="hs-identifier hs-var">inst</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-914"></span><span>
</span><span id="line-915"></span><span class="hs-comment">---------------</span><span>
</span><span id="line-916"></span><span class="annot"><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-type">insert_overlapping</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-type">InstMatch</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-type">InstMatch</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Core.InstEnv.html#InstMatch"><span class="hs-identifier hs-type">InstMatch</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-917"></span><span class="hs-comment">-- ^ Add a new solution, knocking out strictly less specific ones</span><span>
</span><span id="line-918"></span><span class="hs-comment">-- See Note [Rules for instance lookup]</span><span>
</span><span id="line-919"></span><span id="insert_overlapping"><span class="annot"><span class="annottext">insert_overlapping :: InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
</span><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-var hs-var">insert_overlapping</span></a></span></span><span> </span><span id="local-6989586621680915768"><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915768"><span class="hs-identifier hs-var">new_item</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915768"><span class="hs-identifier hs-var">new_item</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-920"></span><span class="annot"><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-var">insert_overlapping</span></a></span><span> </span><span id="local-6989586621680915767"><span class="annot"><span class="annottext">new_item :: InstMatch
</span><a href="#local-6989586621680915767"><span class="hs-identifier hs-var">new_item</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span id="local-6989586621680915766"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915766"><span class="hs-identifier hs-var">new_inst</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[DFunInstType]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span id="local-6989586621680915765"><span class="annot"><span class="annottext">old_item :: InstMatch
</span><a href="#local-6989586621680915765"><span class="hs-identifier hs-var">old_item</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span id="local-6989586621680915764"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915764"><span class="hs-identifier hs-var">old_inst</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">[DFunInstType]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621680915763"><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915763"><span class="hs-identifier hs-var">old_items</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-921"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915762"><span class="hs-identifier hs-var">new_beats_old</span></a></span><span>        </span><span class="hs-comment">-- New strictly overrides old</span><span>
</span><span id="line-922"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915761"><span class="hs-identifier hs-var">old_beats_new</span></a></span><span>
</span><span id="line-923"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915766"><span class="hs-identifier hs-var">new_inst</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915760"><span class="hs-operator hs-var">`can_override`</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915764"><span class="hs-identifier hs-var">old_inst</span></a></span><span>
</span><span id="line-924"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
</span><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-var">insert_overlapping</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915767"><span class="hs-identifier hs-var">new_item</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915763"><span class="hs-identifier hs-var">old_items</span></a></span><span>
</span><span id="line-925"></span><span>
</span><span id="line-926"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915761"><span class="hs-identifier hs-var">old_beats_new</span></a></span><span>        </span><span class="hs-comment">-- Old strictly overrides new</span><span>
</span><span id="line-927"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621680915762"><span class="hs-identifier hs-var">new_beats_old</span></a></span><span>
</span><span id="line-928"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915764"><span class="hs-identifier hs-var">old_inst</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915760"><span class="hs-operator hs-var">`can_override`</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915766"><span class="hs-identifier hs-var">new_inst</span></a></span><span>
</span><span id="line-929"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915765"><span class="hs-identifier hs-var">old_item</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915763"><span class="hs-identifier hs-var">old_items</span></a></span><span>
</span><span id="line-930"></span><span>
</span><span id="line-931"></span><span>  </span><span class="hs-comment">-- Discard incoherent instances; see Note [Incoherent instances]</span><span>
</span><span id="line-932"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier hs-var">isIncoherent</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915764"><span class="hs-identifier hs-var">old_inst</span></a></span><span>      </span><span class="hs-comment">-- Old is incoherent; discard it</span><span>
</span><span id="line-933"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
</span><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-var">insert_overlapping</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915767"><span class="hs-identifier hs-var">new_item</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915763"><span class="hs-identifier hs-var">old_items</span></a></span><span>
</span><span id="line-934"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isIncoherent"><span class="hs-identifier hs-var">isIncoherent</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915766"><span class="hs-identifier hs-var">new_inst</span></a></span><span>      </span><span class="hs-comment">-- New is incoherent; discard it</span><span>
</span><span id="line-935"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915765"><span class="hs-identifier hs-var">old_item</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915763"><span class="hs-identifier hs-var">old_items</span></a></span><span>
</span><span id="line-936"></span><span>
</span><span id="line-937"></span><span>  </span><span class="hs-comment">-- Equal or incomparable, and neither is incoherent; keep both</span><span>
</span><span id="line-938"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-939"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915765"><span class="hs-identifier hs-var">old_item</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">InstMatch -&gt; [InstMatch] -&gt; [InstMatch]
</span><a href="GHC.Core.InstEnv.html#insert_overlapping"><span class="hs-identifier hs-var">insert_overlapping</span></a></span><span> </span><span class="annot"><span class="annottext">InstMatch
</span><a href="#local-6989586621680915767"><span class="hs-identifier hs-var">new_item</span></a></span><span> </span><span class="annot"><span class="annottext">[InstMatch]
</span><a href="#local-6989586621680915763"><span class="hs-identifier hs-var">old_items</span></a></span><span>
</span><span id="line-940"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-941"></span><span>
</span><span id="line-942"></span><span>    </span><span id="local-6989586621680915762"><span class="annot"><span class="annottext">new_beats_old :: Bool
</span><a href="#local-6989586621680915762"><span class="hs-identifier hs-var hs-var">new_beats_old</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915766"><span class="hs-identifier hs-var">new_inst</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915759"><span class="hs-operator hs-var">`more_specific_than`</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915764"><span class="hs-identifier hs-var">old_inst</span></a></span><span>
</span><span id="line-943"></span><span>    </span><span id="local-6989586621680915761"><span class="annot"><span class="annottext">old_beats_new :: Bool
</span><a href="#local-6989586621680915761"><span class="hs-identifier hs-var hs-var">old_beats_new</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915764"><span class="hs-identifier hs-var">old_inst</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915759"><span class="hs-operator hs-var">`more_specific_than`</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915766"><span class="hs-identifier hs-var">new_inst</span></a></span><span>
</span><span id="line-944"></span><span>
</span><span id="line-945"></span><span>    </span><span class="hs-comment">-- `instB` can be instantiated to match `instA`</span><span>
</span><span id="line-946"></span><span>    </span><span class="hs-comment">-- or the two are equal</span><span>
</span><span id="line-947"></span><span>    </span><span id="local-6989586621680915758"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915758"><span class="hs-identifier hs-var">instA</span></a></span></span><span> </span><span id="local-6989586621680915759"><span class="annot"><span class="annottext">more_specific_than :: ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915759"><span class="hs-operator hs-var hs-var">`more_specific_than`</span></a></span></span><span> </span><span id="local-6989586621680915757"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915757"><span class="hs-identifier hs-var">instB</span></a></span></span><span>
</span><span id="line-948"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe TCvSubst -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="../../base/src/Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[Type] -&gt; [Type] -&gt; Maybe TCvSubst
</span><a href="GHC.Core.Unify.html#tcMatchTys"><span class="hs-identifier hs-var">tcMatchTys</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var hs-var">is_tys</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915757"><span class="hs-identifier hs-var">instB</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">ClsInst -&gt; [Type]
</span><a href="GHC.Core.InstEnv.html#is_tys"><span class="hs-identifier hs-var hs-var">is_tys</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915758"><span class="hs-identifier hs-var">instA</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-949"></span><span>
</span><span id="line-950"></span><span>    </span><span id="local-6989586621680915756"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915756"><span class="hs-identifier hs-var">instA</span></a></span></span><span> </span><span id="local-6989586621680915760"><span class="annot"><span class="annottext">can_override :: ClsInst -&gt; ClsInst -&gt; Bool
</span><a href="#local-6989586621680915760"><span class="hs-operator hs-var hs-var">`can_override`</span></a></span></span><span> </span><span id="local-6989586621680915755"><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915755"><span class="hs-identifier hs-var">instB</span></a></span></span><span>
</span><span id="line-951"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isOverlapping"><span class="hs-identifier hs-var">isOverlapping</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915756"><span class="hs-identifier hs-var">instA</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">ClsInst -&gt; Bool
</span><a href="GHC.Core.InstEnv.html#isOverlappable"><span class="hs-identifier hs-var">isOverlappable</span></a></span><span> </span><span class="annot"><span class="annottext">ClsInst
</span><a href="#local-6989586621680915755"><span class="hs-identifier hs-var">instB</span></a></span><span>
</span><span id="line-952"></span><span>       </span><span class="hs-comment">-- Overlap permitted if either the more specific instance</span><span>
</span><span id="line-953"></span><span>       </span><span class="hs-comment">-- is marked as overlapping, or the more general one is</span><span>
</span><span id="line-954"></span><span>       </span><span class="hs-comment">-- marked as overlappable.</span><span>
</span><span id="line-955"></span><span>       </span><span class="hs-comment">-- Latest change described in: #9242.</span><span>
</span><span id="line-956"></span><span>       </span><span class="hs-comment">-- Previous change: #3877, Dec 10.</span><span>
</span><span id="line-957"></span><span>
</span><span id="line-958"></span><span class="hs-comment">{-
Note [Incoherent instances]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
For some classes, the choice of a particular instance does not matter, any one
is good. E.g. consider

        class D a b where { opD :: a -&gt; b -&gt; String }
        instance D Int b where ...
        instance D a Int where ...

        g (x::Int) = opD x x  -- Wanted: D Int Int

For such classes this should work (without having to add an &quot;instance D Int
Int&quot;, and using -XOverlappingInstances, which would then work). This is what
-XIncoherentInstances is for: Telling GHC &quot;I don't care which instance you use;
if you can use one, use it.&quot;

Should this logic only work when *all* candidates have the incoherent flag, or
even when all but one have it? The right choice is the latter, which can be
justified by comparing the behaviour with how -XIncoherentInstances worked when
it was only about the unify-check (note [Overlapping instances]):

Example:
        class C a b c where foo :: (a,b,c)
        instance C [a] b Int
        instance [incoherent] [Int] b c
        instance [incoherent] C a Int c
Thanks to the incoherent flags,
        [Wanted]  C [a] b Int
works: Only instance one matches, the others just unify, but are marked
incoherent.

So I can write
        (foo :: ([a],b,Int)) :: ([Int], Int, Int).
but if that works then I really want to be able to write
        foo :: ([Int], Int, Int)
as well. Now all three instances from above match. None is more specific than
another, so none is ruled out by the normal overlapping rules. One of them is
not incoherent, but we still want this to compile. Hence the
&quot;all-but-one-logic&quot;.

The implementation is in insert_overlapping, where we remove matching
incoherent instances as long as there are others.



************************************************************************
*                                                                      *
        Binding decisions
*                                                                      *
************************************************************************
-}</span><span>
</span><span id="line-1010"></span><span>
</span><span id="line-1011"></span><span class="annot"><a href="GHC.Core.InstEnv.html#instanceBindFun"><span class="hs-identifier hs-type">instanceBindFun</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#TyCoVar"><span class="hs-identifier hs-type">TyCoVar</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Core.Unify.html#BindFlag"><span class="hs-identifier hs-type">BindFlag</span></a></span><span>
</span><span id="line-1012"></span><span id="instanceBindFun"><span class="annot"><span class="annottext">instanceBindFun :: DFunId -&gt; BindFlag
</span><a href="GHC.Core.InstEnv.html#instanceBindFun"><span class="hs-identifier hs-var hs-var">instanceBindFun</span></a></span></span><span> </span><span id="local-6989586621680915753"><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915753"><span class="hs-identifier hs-var">tv</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">DFunId -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#isOverlappableTyVar"><span class="hs-identifier hs-var">isOverlappableTyVar</span></a></span><span> </span><span class="annot"><span class="annottext">DFunId
</span><a href="#local-6989586621680915753"><span class="hs-identifier hs-var">tv</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BindFlag
</span><a href="GHC.Core.Unify.html#Skolem"><span class="hs-identifier hs-var">Skolem</span></a></span><span>
</span><span id="line-1013"></span><span>                   </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>              </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BindFlag
</span><a href="GHC.Core.Unify.html#BindMe"><span class="hs-identifier hs-var">BindMe</span></a></span><span>
</span><span id="line-1014"></span><span>   </span><span class="hs-comment">-- Note [Binding when looking up instances]</span><span>
</span><span id="line-1015"></span><span>
</span><span id="line-1016"></span><span class="hs-comment">{-
Note [Binding when looking up instances]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When looking up in the instance environment, or family-instance environment,
we are careful about multiple matches, as described above in
Note [Overlapping instances]

The key_tys can contain skolem constants, and we can guarantee that those
are never going to be instantiated to anything, so we should not involve
them in the unification test.  Example:
        class Foo a where { op :: a -&gt; Int }
        instance Foo a =&gt; Foo [a]       -- NB overlap
        instance Foo [Int]              -- NB overlap
        data T = forall a. Foo a =&gt; MkT a
        f :: T -&gt; Int
        f (MkT x) = op [x,x]
The op [x,x] means we need (Foo [a]).  Without the filterVarSet we'd
complain, saying that the choice of instance depended on the instantiation
of 'a'; but of course it isn't *going* to be instantiated.

We do this only for isOverlappableTyVar skolems.  For example we reject
        g :: forall a =&gt; [a] -&gt; Int
        g x = op x
on the grounds that the correct instance depends on the instantiation of 'a'
-}</span><span>
</span><span id="line-1041"></span></pre></body></html>